Hi, my sql statement is something like this below
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 i am haveing here is that the column name in the select statement which is given as [col1] is a dynamic value. So i am trying 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 an error that @OLD_NAV_VALUE has to be declared. So i tried declaring @OLD_NAV_VALUE inside the EXEC statement. But if i do this i am not able to use the same outside the EXEC statement.
Please let me know how to do this.