1

There are several status an the status table. I want query like that.

select * from command where status <> 's' and status<> 'sc'

But query retrieve data with 'Status' S. What was the issue on that?

1
  • What is the data type and collation of the column status?
    – Nick.Mc
    Commented Aug 11, 2015 at 5:06

3 Answers 3

6

Is the status in the DB S or s?

Try

select * from command where lower(status) NOT IN ('s', 'sc')
3

Just try it.. No need to check lower or caps. It searches all letter (not case sensitive).

select * from command where status NOT IN ('s', 'sc')

If you want to add condition with case sensitive, then you have to use like this..

select * from command where status COLLATE Latin1_General_CS_AS NOT IN ('s', 'sc')
1

The checks Col <> 's' depends on the collation of the columns. If the collation is case insensitive, then 'S' = 's' and your checks will not return S. If your collation is case sensitive which I believe is the case, will return S.

For example note the following two collations Latin1_General_CI_AS_KS_WS and Latin1_General_CS_AS_KS_WS. Note the difference in case CI and CS.

SELECT 'S' WHERE 'S' <> 's' COLLATE Latin1_General_CI_AS_KS_WS

Does not return anything

SELECT 'S' WHERE 'S' <> 's' COLLATE Latin1_General_CS_AS_KS_WS

Returns S

Coming back to your query. If this case insensitive check is a one time thing you can either as suggested by other answers do a UPPER(Col) / LOWER(Col) or use COL COLLATE Latin1_General_CI_AS_KS_WS.

If all comparisons should be case insensitive, I would suggest changing the collation of the column itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.