Hi,
I want to set the result of EXEC(@SQL) to a variable. That is, I want the MAX(ProductionDate) to be stored in a variable called @MaxTradeDate.
It has to be dynamic because @myTable will be a parameter whose value will change.
SET @SQL =
'SELECT MAX(ProductionDate) FROM ' + @myTable
SET @MaxTradeDate = EXEC(@SQL)
I get this error:
Msg 156, Level 15, State 1, Procedure myProc, Line 9
Incorrect syntax near the keyword 'SET'.
Thanks much
I want to set the result of EXEC(@SQL) to a variable. That is, I want the MAX(ProductionDate) to be stored in a variable called @MaxTradeDate.
It has to be dynamic because @myTable will be a parameter whose value will change.
SET @SQL =
'SELECT MAX(ProductionDate) FROM ' + @myTable
SET @MaxTradeDate = EXEC(@SQL)
I get this error:
Msg 156, Level 15, State 1, Procedure myProc, Line 9
Incorrect syntax near the keyword 'SET'.
Thanks much