March 1, 2009 at 2:20 am
Hi every body,
I want column name and current month, I tried as follows but fails
SELECT
DATEPART(MONTH,
CASE WHEN PromiseDateG IS NULL THEN DateNeededG ELSE PromiseDateG END)
AS DATENAME(MONTH(GETDATE()))
FROM
PordmstrDT
March 1, 2009 at 7:27 am
Column names are a fixed item in sql, so
to do that you would have to generate dynamic sql:crazy:
or use a form of pivot function.
Declare @sqlstmt as varchar(500)
Set @sqlstmt = 'select your_casestatement as [' + DATENAME(MONTH,GETDATE())
+']'
exec (@sqlstmt)
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 1, 2009 at 6:32 pm
See the following articles... the first one explains some of the performance problems with using PIVOT instead of building good ol' fashioned cross-tabs and the second one explains one method for dynamic column names.
http://www.sqlservercentral.com/articles/T-SQL/63681/
http://www.sqlservercentral.com/articles/cross+tab/65048/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply