mysql - How to put single quotes around variables in a dynamic query -
mysql - How to put single quotes around variables in a dynamic query -
i trying build dynamic query. @query set query string , want dynamically add together clause. works, except isn't putting single quotes around strings in case @val. causes error. how include single quotes adds them correctly?
this i've tried:
set @query = @query + ' ' + '' + @param + ' ' + @operator + ' ' + '' + @val + '' ;
thanks!
you have place quote in between quotes, escape doesn't break code. following:
set @query = @query + ' ' + '' + @param + ' ' + @operator + ' ' + '\'' + @val + '\'' ;
edit: eric anderson's reply works well. take mysql 5.0 manual
a “'” within string quoted “'” may written “''”.
mysql dynamic-sql
Comments
Post a Comment