dynamic syntax comma

  • dynamic sql error

    if u paste this in ur query window

    declare @name sysname

    set @Name = 'A_NEW_York'

    select @name where @name like 'a\_[a-z][a-z][a-z]\_%' ESCAPE '\' --works fine

    --

    declare @name sysname

    set @Name = 'ANEWYork'

    select @name where @name like 'a\_[a-z][a-z][a-z]\_%' ESCAPE '\' --works fine

    But due to some issues i m dont want to use ESCAPE in my code

    declare @name sysname

    set @Name = 'A_NEW_York'

    select @name where @name like 'a''_''[a-z][a-z][a-z]''_''%'

    its not selecting anything... I have tried different combinations using commas

    but looks like some syntax error..

  • Try this:

    declare @name sysname

    set @Name = 'A_NEW_York'

    select @name where @name like 'a[_][a-z][a-z][a-z][_]%'

    Square-brackets around an underscore make it a literal-string, instead of a variable. Test it with this:

    declare @name sysname

    set @Name = 'AxNEW_York'

    select @name where @name like 'a[_][a-z][a-z][a-z][_]%'

    If it were still a variable, it would select the value, because it would accept the "x".

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 2 posts - 1 through 1 (of 1 total)

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