Does any one know how you can set a variable with a column name then call it in a select statement?
select * from ksa_running_totals
DECLARE @week1 as datetime
SET @week1 = 'col' & GETDATE()
This code works OK to get the column name. What I need to do now is do a select which selects this column plus other columns.
SELECT col1, col2, @week1
FROM table1
This code doesn't work as it just puts the contents of the variable in a new column on each row.
Can anyone help
Cheers
Adam
select * from ksa_running_totals
DECLARE @week1 as datetime
SET @week1 = 'col' & GETDATE()
This code works OK to get the column name. What I need to do now is do a select which selects this column plus other columns.
SELECT col1, col2, @week1
FROM table1
This code doesn't work as it just puts the contents of the variable in a new column on each row.
Can anyone help
Cheers
Adam