I am trying to run a query in SQL 2008 by doing:
@query varchar(max) SET @query = \'SELECT * FROM Table WHERE [Name] = \' \'Karl\' \' \' EXEC(@query)
Simply escape the apostrophes by using the escaping bar \ like this 'SELECT * FROM Table WHERE [Name] = ' \'Karl\' ' '
Hope it helps