1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

soo redicilous prob with escape charachters

Discussion in 'SQL Server' started by mad_girl, Aug 27, 2007.

  1. mad_girl

    mad_girl New Member

    Joined:
    Aug 14, 2007
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    the problem is i wanna make this piece of code work and i don know what the problem is , i think it's with the combination of charachters ' and "
    Code:
    set @query=@query+ "cast(ID as varchar) like'%'+ltrim(@id)+'%' " 
    set @query=@query+ @option+" userName like'%'+ltrim(@name)+'%' "
    set @query=@query+ @option+" cast(referrer as varchar) like'%'+ltrim(@ref)+'%' "
    set @query=@query+ @option+" age=cast(@age as int) "
    exec(@query)
    
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    That looks scary!
     
  3. sql-programs

    sql-programs New Member

    Joined:
    Oct 21, 2009
    Messages:
    14
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Software Developer
    Home Page:
    Try this query,

    Code:
    set @query=@query+ 'cast(ID as varchar) like ''%'+ltrim(@id)+'%'''
    set @query=@query+ @option+' userName like ''%' +ltrim(@name)+'%'''
    set @query=@query+ @option+' cast(referrer as varchar) like ''%'+ltrim(@ref)+'%'''
    set @query=@query+ @option+' age=cast(@age as int) '
     
    shabbir likes this.

Share This Page