I have the following code snippet from a SQL Server Stored Procedure.
DECLARE @sql nvarchar(Max)
SET @sql = N'
WITH CTE AS
(
SELECT * FROM #TEMP WHERE ...
),
Track AS
(
SELECT *,
CASE WHEN 1B1 = "Track" AND (QTRK_1B1 = "2D QT" OR QTRK_1B1 = "3D QT") THEN "Yes" ELSE "No" END AS Tracking
FROM CTE
),
... '
Exec sp_executesql @sql, N'@AirTarget nvarchar(25), @GroundTracker nvarchar(25)', @AirTarget, @GroundTracker
I am not sure what I am doing wrong here. When I execute the stored procedure, I am getting errors like:
Invalid Column Name 'Track'
Invalid Column Name '2D QT'
Invalid Column Name '3D QT'
Invalid Column Name 'Yes'
Invalid Column Name 'No'
But those are not column names from the table. I have Googled and cannot figure out what I am doing wrong.
I have tried surrounding those values with single quotes, and I have tried removing the quotes from around those values and nothing works. Any help would be appreciated