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 2008 Forums
 Transact-SQL (2008)
 Column to be concatenated from SUM() function

Author  Topic 

thiyagu2001
Starting Member

1 Post

Posted - 2011-07-22 : 03:14:18
Hi All,
I would like to have the header name with year variable to added with the SUM().
please check the below example:
<code>`
DECLARE @lJanACTName VARCHAR(30),
@lyear Int
set @lyear = 2011
SET @lJanACTName = 'Jan Act ' + CAST(@lYear AS VARCHAR(10))
SELECT @lJanACTName
SELECT sum(AuditID) as @lJanACTName
from ARMS_AuditLog
GROUP BY AuditID `
</code>

My O/P should be **"Jan Act 2011" as a column name**.....

Please advice.



- Thiyagu

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-07-22 : 04:15:46

what you want calls for Dynamic SQL

do read this http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -