comparing strings

  •   Hi does anyone know the SQL for comparing the first letter of a string to a letter of your choosing????

      Cheers Ehsan

  • IF LEFT('Letter', 1) = 'L'
        PRINT 'Correct'
    ELSE
        PRINT 'Wrong'
    







    **ASCII stupid question, get a stupid ANSI !!!**

  • Or in a query :

    where MyColum like @Letter + '%'

  • wow - remi and noel online at the same time - this hasn't happened for a long time..

    here're some more - "just for the fun of it"..

    
    select * from myTable where left(myCol, 1) = 'L'
    
    select * from myTable  where charindex('L', myCol, 1) = 1
    
    select * from myTable  where myCol like 'L%' 
    
    select * from myTable  where right(reverse(myCol), 1) = 'L'
    
    select * from myTable  where substring(myCol, 1, 1) = 'L'
    







    **ASCII stupid question, get a stupid ANSI !!!**

  • Cool, pick out the right answer from that list now .

  • He he its been a while I had to do many many things at once and the light still not at the end of the tunnel

     

     


    * Noel

  • It's certainly been a looooooooooong while - almost feels like another lifetime - the "good old days"...

    remi - I'll let the original poster pick the "right" answer...though my preference would still be to go with "left" -







    **ASCII stupid question, get a stupid ANSI !!!**

  • Since when is left sargable?

  • moral of the story - "search" all you want and "argue" all you want...remi's solution is ALWAYS the only right one...I only said "left" for that play on words that I can never resist...

    btw - what if the column is not indexed ?!







    **ASCII stupid question, get a stupid ANSI !!!**

  • That's it... I'm never comming back. I'm not always right but if you guys can't live with the fact that I'm rarely wrong then Goodbye.

  • oh I'm used to the fact that you're "rarely wrong"...AND since I'm not one of the "guys"..hopefully whoever you're addressing in your post will come along and respond before you "never come back"!!!!







    **ASCII stupid question, get a stupid ANSI !!!**

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply