October 28, 2010 at 10:31 am
Hi,
I am trying to execute this statement and I suppose there is a problem in apostrophes, but I don't know how to make it work.
Exec ('SELECT DISTINCT ' + @DefaultSelect + ' FROM ' + @FromClause + ' WHERE FirstName LIKE 'Peter' ');
Any suggestions?
Thanks
October 28, 2010 at 11:19 am
dtopicdragovic (10/28/2010)
Hi,I am trying to execute this statement and I suppose there is a problem in apostrophes, but I don't know how to make it work.
Exec ('SELECT DISTINCT ' + @DefaultSelect + ' FROM ' + @FromClause + ' WHERE FirstName LIKE 'Peter' ');
Any suggestions?
Thanks
When you are trying to use quotes with a quoted string, you need to double-up on the embedded quotes. Specifically around the constant in the where clause:
Exec ('SELECT DISTINCT ' + @DefaultSelect + ' FROM ' + @FromClause + ' WHERE FirstName LIKE ''Peter'' ');
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 28, 2010 at 11:26 am
It worked !
Thanks a lot!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply