my sql statement looks something like this:
DECLARE @OLD_NAV_VALUE AS INT
DECLARE @FINAL AS INT
SELECT @OLD_NAV_VALUE = [col1] from TBL_BA where DATE = @id_Date
SET @FINAL = @OLD_NAV_VALUE * 50
But the problem is that the column name in the select expression specified as [col1] is a dynamic value. So I am trying to do something like this below.
DECLARE @OLD_NAV_VALUE AS INT
DECLARE @FINAL AS INT
EXEC('SELECT @OLD_NAV_VALUE = [' + @DYNAMIC_COL_NAME + '] from TBL_BA where DATE = ' + @id_Date)
SET @FINAL = @OLD_NAV_VALUE * 50
this gives the error that @OLD_NAV_VALUE should declare. So I tried to declare @OLD_NAV_VALUE inside the EXEC statement. But if I do, I cannot use it outside the EXEC statement.
Please let me know how to do this.
Vinod source
share