I have created the following procedure to finally get the value (and not the column name at the end). However if using just the declared @ColumnName in the last query I just see the column name 'XXX' and not the value for XXX at that row.
I have the following:
DECLARE @ColumnName AS VARCHAR(50)
SET @ColumnName = (select column_name FROM INFORMATION_SCHEMA.COLUMNS where table_name = 'History' and ORDINAL_POSITION = 2 )
SELECT @ColumnName from kat.[dbo].[History]
What I would like to get is the following results :
select XXX from kat.[dbo].[History]
Even the @ColumName has the value of XXX this is not working.
In the left I get my result (always the name of the column, and it the right is the desired value)
1-XXX, The value from XXX
2-XXX, the next value from XXX
3-XXX, the next value from XXX
Many thanks in advance,
Kat