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

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'

Related

Sql query to find records with column value is blank

I'm trying to find records with Column value is blank. as you can see in the table I have records with following values when I fire a Distinct query on the Column MOVE_STU.
now I can find all the record with column value related to (1,2,3,4 and 6) but I'm not able to find the records with Column Value related to (5). as there are Thousands of record in the table i'm not able to figure out how should I write query in order to get these records. Kindly help. Thanks in Advance. :)
Use trim and comparison with empty string to get records that contain only whitespaces:
SELECT *
FROM your_table
WHERE LTRIM(RTRIM(MOVE_STU)) = ''
Try something like this:
SELECT * FROM YourTable WHERE LTRIM(RTRIM(YourField)) = ''
This will give you all matches that are empty, or have only whitespace.
How about this ?
SELECT * FROM YourTable WHERE MOVE_STU = ''
SELECT * FROM YourTable WHERE ISNULL(MOVE_STU,'') = ''
You can try this:
If your datatype is int then you have to change in varchar
ALTER TABLE [tbl_name] ALTER COLUMN [MOVE_STU] [VARCHAR(50)];
then run the query:
SELECT * FROM [tbl_name] WHERE MOVE_STU IS NULL;

select query in sqlite doesn't return anything

I'm using the Firefox sqlite manager addon and I have a database table named - drinktable. I need to extract all the columns where the title matches a certain string. This is the query I am running right now -
SELECT * FROM drinktable where title = 'First Drink';
But it won't return anything. It just shows the 4 columns in the database, but nothing in those columns. Can someone please tell me why ?
I have a database table named - drinktable.
One thing in your question. Your table name is drinktable and you are querying against first, is it a typo. In SQL Select statement you specify table name after from and column name in where clause
SELECT * FROM drinktable where first = 'First Drink';
Select * from <TableName> where <ColumnName> = 'Value to compare';
If your table name is first and column name is drinktable then chances are that there are now row(s) with column drinktable set to 'First Drink'. You might have spaces or some other characters. Try
SELECT * FROM first where drinktable like '%First Drink%';
EDIT:
Based on your edited question, chances are you have spaces or some other characters, try:
SELECT * FROM drinktable where title like '%First Drink%';

Simple Select statement does not return any result

I have one database table name test123 and having column name. And it contains the data like 'nir,kal,man' Now, when i am querying the table with select statement as per below :
select * from test123 where name = 'nir,kal,man';
But this will not return any result...Why this happened.? How i have to write query so that will return the result?
I am using Sql server 2008.
Thanks...!
= operator returns exact match, so if your cell contain data "like" that you need to use LIKE operator:
select * from test123 where name like '%nir,kal,man%'
where % will be replaced with any set of characters.
Also check that you're targeting correct database by using full name
select * from yourdb.dbo.test123 where....
if Nir is in first row Kal in 2nd row and man is in 3rd row then you should write query like this
select * from test123 where name in ('nir','kal','man')

sql searching multiple words in a string

What is the most efficient and elegant SQL query looking for a string containing the words "David", "Moses" and "Robi". Assume the table is named T and the column C.
Select * from table where
columnname like'%David%' and
columnname like '%Moses%' and columnname like'%Robi%'
In SQL Server 2005+ with Full-Text indexing switched on, I'd do the following:
SELECT *
FROM T
WHERE CONTAINS(C, '"David" OR "Robi" OR "Moses"');
If you wanted your search to bring back results where the result is prefixed with David, Robi or Moses you could do:
SELECT *
FROM T
WHERE CONTAINS(C, '"David*" OR "Robi*" OR "Moses*"');
Here is what I uses to search for multiple words in multiple columns - SQL server
Hope my answer help someone :) Thanks
declare #searchTrm varchar(MAX)='one two three ddd 20 30 comment';
--select value from STRING_SPLIT(#searchTrm, ' ') where trim(value)<>''
select * from Bols
WHERE EXISTS (SELECT value
FROM STRING_SPLIT(#searchTrm, ' ')
WHERE
trim(value)<>''
and(
BolNumber like '%'+ value+'%'
or UserComment like '%'+ value+'%'
or RequesterId like '%'+ value+'%' )
)
If you care about the sequence of the terms, you may consider using a syntax like
select * from T where C like'%David%Moses%Robi%'
Oracle SQL :
select *
from MY_TABLE
where REGEXP_LIKE (company , 'Microsodt industry | goglge auto car | oracles database')
company - is the database column name.
results - this SQL will show you if company column rows contain one of those companies (OR phrase)
please note that : no wild characters are needed, it's built in.
more info at : http://www.techonthenet.com/oracle/regexp_like.php
if you put all the searched words in a temporaray table say #tmp and column col1, then you could try this:
Select * from T where C like (Select '%'+col1+'%' from #temp);
Maybe EXISTS can help.
and exists (select 1 from #DocumentNames where pcd.Name like DocName+'%' or CD.DocumentName like DocName+'%')
Oracle SQL:
There is the "IN" Operator in Oracle SQL which can be used for that:
select
namet.customerfirstname, addrt.city, addrt.postalcode
from schemax.nametable namet
join schemax.addresstable addrt on addrt.adtid = namet.natadtid
where namet.customerfirstname in ('David', 'Moses', 'Robi');

SQL select using condition that a column starts with a certain string

I am using sql.
How to select all items from a table.
where a column (varchar) path is start with a certain string : "stringABC"
select * from ATable where path like 'stringABC';
The above sql is wrong, can any one help me to fix it?
Many thanks!
select *
from ATable
where path like 'stringABC%'
select * from ATAble where path like 'string%'