Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Today's date as column name

Author  Topic 

AndyK
Starting Member

2 Posts

Posted - 2011-01-13 : 04:56:29
Hi All,
long time lurker, first time poster!

I am trying to add todays date as a column name to a simple select statement.

Any ideas how I go about this?

Many Thanks in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-13 : 05:14:35
Do this in the application and not in T-SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-01-13 : 05:49:18
I strongly suggest that you follow what Tara said.But just for sake of your knowledge you can do this.


create table #t (dt datetime)
insert #t
select getdate()
declare @col varchar(20)=getdate()
declare @sql nvarchar(100)='select dt as ''' + quotename(@col) + ''' from #t'
exec sp_executesql @sql,N'@col varchar(100)',@col=getdate;

drop table #t





PBUH

Go to Top of Page

AndyK
Starting Member

2 Posts

Posted - 2011-01-13 : 06:01:14
Thank you both for your replies!

Andy
Go to Top of Page
   

- Advertisement -