Select row which has apostrophe value postgresql - sql

I want to select rows which has apostrophe value postgresql:
select * from table where column like '%'||chr(39)||'%'
But it doesn't work.
Table buku:
id new_issn
------------- --------
1.003.111.641 ''
1.003.111.642 ''
1.003.111.643 125698
select * from buku where new_issn like '%'||chr(39)||'%'

An apostrophe can be escaped with another apostrophe. Try this:
select * from table where column like '%''%'
Reference: Postgresql docs.

Related

MS Query with comma separated parameters

How to make MS Query work with comma separated parameters in Excel cell?
My query is:
SELECT *
FROM ABC
WHERE Id in (?)
When I put id number for example "1" the query works, but I want to put into a parameters cell a few id's 1, 2, 3, 4 etc, but then I'm trying to to this the query doesn't work... How can I put parameter with comma separated values?
there is 2 diff way to do it:
select * from abc where id in ('1','2','3') etc but not in excel - maybe use notepad++
second way :)
select * from abc where (id like '1' or id like '2' or id like '3') etc
:)
You can use IN in you sql query.
SELECT column_name(s)
FROM table_name
WHERE column_name IN (1,2,3,4);
also try to use BETWEEN with comma as parameters.
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

How to select the column names of a table where column data contains '%' in the values?

How to select the column names of a table where column data contains '%' in the values?
Eg: In the table COMP there are two columns(Addr, Comp_Name) which has data containing '%' in its string. So my query should return those column_names(Addr, Comp_Name)
I dont get you right but i thing this will help you
You can use the escape identifier
--Queries
-- for %
select * from test_a where col1 like '%\%%' escape '\';
--for _
select * from test_a where col1 like '%\_%' escape '\';

SQL pattern matching in search conditions

I have a table with a field name.
For a given name like ABC I want to get the records with that name and the records which have an L appended at the end.
So for ABC I want all records with name either ABC or ABCL.
I tried getting the records using the following code but it doesn't work.
SELECT * FROM tbl
WHERE name like "ABC[|L]"
I am using TSQL.
How can pattern match these names?
Use this SQL:
SELECT * FROM tbl WHERE name IN ('ABC', 'ABCL')
If you are using this SQL within a Stored Procedure / Function, something like following would work. Assuming, you are passing in the value for name in a #name variable.
SELECT * FROM tbl WHERE name IN (#name, #name + 'L')
Use the IN operator.
SELECT *
FROM tbl
WHERE name IN ('ABC', 'ABCL')
In case you will be using variables instead of literal strings, try this:
select *
from tbl
where name like (#YourName + #ExtraLetter)
or name = #YourName

SQL search on part of column

Let's say I have multiple 6 character Alphanumeric strings. abc123, abc231, abc456, cba123, bac231, and bac123.
Basically I want a select statement that can search and list all the abc instances.
I just want a select statement that can list all instances with keyword "abc".
Use LIKE and wildcards %
SELECT *
FROM yourtable
WHERE yourfield LIKE '%abc%'
Input
yourfield
abc123
abc231
abc456
cba123
bac231
bac123
Output:
yourfield
abc123
abc231
abc456
SQL Fiddle:
Could you try like this way
SELECT *
FROM yourtable
WHERE field LIKE '%a%' Or field LIKE '%b%' Or field LIKE '%c%'
Select * from tablename
where yourfield like 'yourconstantcharacters%'
You can use LIKE operator in sql
Starting With Case
Select * From Table Where Column LIKE 'abc%';
Ending With Case
Select * From Tablo Where Column Like '%abc';
Contains With Case
Select * From Table Where Column LIKE '%abc%';
So If you want to use escape character in LIKE condition , you must make small changes on your condition
For Example :
SELECT * FROM Table WHERE column LIKE '!%' escape '!';
More information for you is here

sql server matching field containing "$$" and "%"

One of my column in sql table contain values like
$$ADC.ES%32,A
How can I match this in my select where clause?
Select .... From .... Where ColumnName = '$$ADC.ES%32,A'
Thanks
it should find with your query any way try this
select * from table where name like '$$ADC.ES%32,A'