May 19, 2010 at 1:23 am
Hi,
I want to compare charaters in the case sesitive form.
I mean I would be result of following query <> 0. How can I do that?
SELECT CHARINDEX('x', 'X') -- Result is 1 but i want result be 0!
Please help me.
May 19, 2010 at 2:01 am
You can make use of the ASCII funtion!
Like this
SELECT ASCII('x') -- = 120
SELECT ASCII('X') -- = 88
Now u can compare both the fields and when then match do something when they dont do other thing!
Hope this helps you!
May 19, 2010 at 2:24 am
Or by using a case sensitive collation
SELECT CHARINDEX('x' collate SQL_Latin1_General_CP1_CS_AS, 'X' collate SQL_Latin1_General_CP1_CS_AS)
May 19, 2010 at 2:27 am
But how about this?
SELECT CHARINDEX('X', 'abcdx')
If we want compare just two characters your way is correct. But at this case we cannot do this.
Can I use something like COLATE in the code?
May 19, 2010 at 2:38 am
Dave Ballantyne (5/19/2010)
Or by using a case sensitive collation
SELECT CHARINDEX('x' collate SQL_Latin1_General_CP1_CS_AS, 'X' collate SQL_Latin1_General_CP1_CS_AS) [/cod]
Thanks. It is exactly what I was looking for!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply