July 17, 2012 at 9:59 am
Hi,
I have a variable (date), that I want to use as a column header. Is this possible?
Regards,
Jason
July 17, 2012 at 10:06 am
Out of interest, can you explain why you need this?
Should be easy enough via some dynamic SQL - not sure it will be possible otherwise.
July 17, 2012 at 10:07 am
July 19, 2012 at 9:37 am
not sure about your exact problem.
can't you use "AS" in your select statement ?
select column as Date from ...
July 20, 2012 at 1:36 pm
Yes you can.
Just use a dynamic query. Something like this
DECLARE @SQL_string AS varchar(200)
DECLARE @Column_Name AS varchar(20)
SET @Column_Name = 'Customer_Number'
SET @SQL_string = 'SELECT CST_Num AS ' + @Column_Name + ', ' + CHAR(13) +
'Revenue, Cost FROM CST_REV_TABLE'
EXEC (SCR_TC_PREP)
Good Luck!
Jacob Milter
July 20, 2012 at 1:48 pm
Ooops!
Just realized that you need to use date variabe...
Here it is:
DECLARE @SQL_string AS varchar(200)
DECLARE @Column_Name AS varchar(20)
DECLARE @Date_Value AS Datetime
SET @Date_Value = GETDATE()
SET @Column_Name = 'Customer_Number'
SET @SQL_string = 'SELECT CST_Num AS ' + @Column_Name + ', ' + CHAR(13) +
'Revenue AS ' + 'Revenue_As_OF_' + REPLACE(CONVERT(VARCHAR(10),GETDATE(),101),'/','') + CHAR(13) +
', Cost FROM CST_REV_TABLE'
--EXEC (@SQL_string)
PRINT (@SQL_string)
Jacob Milter
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy