0

I need help with the format for single qoutes. I am using dynamic sql in an SSRS for error trapping records inserted with single qoutes during bulk imports but I cannot seem to format the actual select statement properly.

SQL Sever 2005 Dev edition. Any help is great.

Declare @DB varchar(99) ------------not used in actual report only for testing in ssms
Set @DB = 'TestDb1' ------------not used in actual report only for testing in ssms
declare @sqlstring nvarchar (3000)
set @sqlstring = 'use ' + @DB + '(select * from Address where Customer like ''%''%'')'
execute sp_executesql @sqlstring

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by BitBlt
0

Change your fourth line to look like this:

set @sqlstring = 'use ' + @DB + '(select * from Address where Customer like ''%''''%'')'

Notice that there are now four single-quotes between the percent-signs. I tested this in SQL2005 Standard Edition, but it should also work with Developer Edition.

0

Thank you man! Definitely life saver............I honestly wrapped my head around that for about 5 hours

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.