-- this does NOT work
SELECT @query =
'SELECT prev_HoleID, prev_dTo, dFrom, info,
CASE WHEN ([prev_dTo] < [dFrom]) THEN "my Msg 1" ELSE "my Msg 2" END -- this is the bit with a problem
FROM #StagCheck
WHERE (NOT (gapCheck IS NULL)) AND (NOT (gapCheck = 0))
ORDER BY prev_HoleID, prev_dTo'
EXECUTE sp_executesql @query
-- this DOES work
SELECT @query =
'SELECT prev_HoleID, prev_dTo, dFrom, info,
CASE WHEN ([prev_dTo] < [dFrom]) THEN 1 ELSE 0 END
FROM #StagCheck
WHERE (NOT (gapCheck IS NULL)) AND (NOT (gapCheck = 0))
ORDER BY prev_HoleID, prev_dTo'
EXECUTE sp_executesql @query
|