Go4Expert

Go4Expert (http://www.go4expert.com/)
-   SQL Server (http://www.go4expert.com/forums/sql-server-forum/)
-   -   soo redicilous prob with escape charachters (http://www.go4expert.com/forums/soo-redicilous-prob-escape-charachters-t6059/)

mad_girl 27Aug2007 11:18

soo redicilous prob with escape charachters
 
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)


pradeep 27Aug2007 15:51

Re: soo redicilous prob with escape charachters
 
That looks scary!

sql-programs 20Nov2009 00:07

Re: soo redicilous prob with escape charachters
 
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) '



All times are GMT +5.5. The time now is 01:32.