CHARINDEX is not Case Sensitive?

  • 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.

  • 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!

  • 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)



    Clear Sky SQL
    My Blog[/url]

  • 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?

  • 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