Friday, January 22, 2016

sql server - TSQL Use ' in string assignment

Trying to use a single quote and assign it to a variable so I can create a dynamic report.




The problem is when I do this:



set @Statequery = (' and PostalState = ' ')  +  @PostalState  + '''


If you do this, print @Statequery, it needs it to look like this.



and postalState = 'QLD'



How do I escape the ' character in this case?



Thanks for your help in advanced,



Ryan

No comments:

Post a Comment