all groups > sql server (alternate) > august 2005 >
You're in the

sql server (alternate)

group:

Show All Months in First Column of Stored Procedure


Show All Months in First Column of Stored Procedure paulmac106 NO[at]SPAM hotmail.com
8/25/2005 3:53:09 PM
sql server (alternate): Hi,

I need what would be similar to a cross tab query in Access.

First Column down needs to show all the months, column headings would
be the day of the month....

1 2 3 4 etc...
Jan
Feb
Mar
etc

how do i set this up in a stored procedure?

any help to get me in the right direction would be greatly
appreciated!!

thanks,
paul
Re: Show All Months in First Column of Stored Procedure jsfromynr
8/25/2005 10:52:39 PM
Hi Paul,
See If this can Help You.

Use NortWind
Create View vwMonths
as
Select DateName(month,dateAdd(mm,MonthId,'20000101'))
MonthName,(MonthId+1) Mon From
(
Select 0 MonthId
Union
Select 1
Union
Select 2
Union
Select 3
Union
Select 4
Union
Select 5
Union
Select 6
Union
Select 7
Union
Select 8
Union
Select 9
Union
Select 10
Union
Select 11
) Cal


Select MonthName,
Max(Case When day(OrderDate) = 1 And Month(OrderDate)=Mon Then
CustomerId End) 'Day 1',
Max(Case When day(OrderDate) = 2 And Month(OrderDate)=Mon Then
CustomerId End) 'Day 2',
Max(Case When day(OrderDate) = 3 And Month(OrderDate)=Mon Then
CustomerId End) 'Day 3',
Max(Case When day(OrderDate) = 4 And Month(OrderDate)=Mon Then
CustomerId End) 'Day 4',
Max(Case When day(OrderDate) = 5 And Month(OrderDate)=Mon Then
CustomerId End) 'Day 5',
Max(Case When day(OrderDate) = 6 And Month(OrderDate)=Mon Then
CustomerId End) 'Day 6'
[quoted text, click to view]


With Warm regards
Jatinder Singh
Re: Show All Months in First Column of Stored Procedure Chandra
8/26/2005 12:00:00 AM

hi paul
you do not have that flexibility. U can try it as:
select 'Jan' as ' ','' as [1], '' as [2], '' as [3]
union
select 'Feb' as ' ','' as [1], '' as [2], '' as [3]
union
select 'Mar' as ' ','' as [1], '' as [2], '' as [3]


best Regards,
Chandra
http://www.SQLResource.com/
http://chanduas.blogspot.com/
---------------------------------------

AddThis Social Bookmark Button