Below is the code where I am getting a columns name dynamically(example F8 is the column name) and storing it in @whcode. What i need is the value that is stored in this column for the where condition specified below. I can see the value stored in the column is 2 but I cannot get it. What it is returning me is the column name itself. How can I get the value in the column. Please help.
declare @count1 int
set @count1 = (select min(srno) from TEMP_STOCK_uPDATE)
declare @whcode varchar(20)
select * from TEMP_STOCK_uPDATE where srno='16091'
set @whcode=(SELECT COLUMN_NAME
FROM Ecata_New.INFORMATION_SCHEMA.COLUMNS
where Table_Name = 'TEMP_STOCK_uPDATE'
and COLUMN_NAME =(select whcode from dbo.temp_stock_map where func=(select func from dbo.temp_stock_map where sr_no=6)))
--select @whcode as 'abcd'
select @whcode as 'abc'
from TEMP_STOCK_uPDATE
where
F1=(select F1 from dbo.TEMP_STOCK_uPDATE where srno=@count1)