I have the following dynamic query to check if today’s date is between the FTOStartDate and FTOEndDDate from a data table.
I am getting the following errors:
Msg 207, Level 16, State 1, Line 18
Invalid column name ‘FTOStartDate’.
Msg 207, Level 16, State 1, Line 19
Invalid column name ‘FTOEndDate’.
All the examples I looked at used a variable in the convert function; I need to use a column name from the data table.
Thanks,
Brad
SET @env = dbo.GetSQLEnvironment();
SET @assigned_claim_table = 'grp_clm_ops_d' + @env + '.dbo.cauDCMFToAssign';
SET @sql = 'SELECT DCMNumber, FTOStartDate ' +
'FROM ' + @assigned_claim_table + ' ' +
'WHERE ' + CONVERT(VARCHAR(10), GETDATE(), 110) +
' NOT BETWEEN ' + CONVERT(VARCHAR(10), FTOStartDate, 110) +
'AND ' + CONVERT(VARCHAR(10), FTOEndDate, 110) + ' '
EXEC sp_executesql @sql;
Why not do:
SQL Server has no issue running converts inside of a dynamic query.