How to Identify name starting with a specific letter without using like operator?

  • Hi All,

    How to Identify name starting with a specific letter without using like operator?

    Please help me out.

    Thanks in advance,

    Sharmi

  • Why do you have the restriction of using the LIKE operator?

    But you can accomplish this for example by using the LEFT or the SUBSTRING operator.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • HanShi (10/25/2013)


    Why do you have the restriction of using the LIKE operator?

    But you can accomplish this for example by using the LEFT or the SUBSTRING operator.

    Bear in mind thet LEFT and SUBSTRING will not use any suitable indexes (possible performance issues) whereas LIKE will.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Could do something odd like this: -

    WHERE Names = STUFF(Names,1,1,'A')

    That'd tell you if the "Names" started with an A.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • sharmili.net (10/25/2013)


    Hi All,

    How to Identify name starting with a specific letter without using like operator?

    Please help me out.

    Why? That's what the LIKE operator is there for, refusing to use the tool most suitable to the problem is strange.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • sharmili.net (10/25/2013)


    Hi All,

    How to Identify name starting with a specific letter without using like operator?

    Please help me out.

    Thanks in advance,

    Sharmi

    It depends... how slow do you want the code to actually run? 😀

    I join Gail in asking, why would anyone want to do such a thing? The courtesy of a reply would be much appreciated.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • It sounds like a homework question to me. The lesson would be that, aside from the obvious approach, there's more than one way to accomplish something. In this case, hopefully eliminating the efficient solution will also be covered in the lesson.

Viewing 7 posts - 1 through 6 (of 6 total)

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