Escape single quote in openquery using dynamic query
问题 I need to retrieve data from a linked server using a parameter, @PickedDate for example. The query works fine if I skip @A and @B, but it always returns an error due to a missing single quote. Please advise, thanks. The query: Declare @OPENQUERY nvarchar(500), @TSQL nvarchar(max), @LinkedServer nvarchar(20), @A varchar(5), @B varchar(5), @PickedDate varchar(8) Set @PickedDate = '20150501' Set @A = 'AAA' Set @B = 'BBB' Set @LinkedServer = 'LinkedServerName' Set @OPENQUERY = 'Select * From