Unix Technical Forum

Show All Months in First Column of Stored Procedure

This is a discussion on Show All Months in First Column of Stored Procedure within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, I need what would be similar to a cross tab query in Access. First Column down needs to ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 09:50 AM
paulmac106@hotmail.com
 
Posts: n/a
Default Show All Months in First Column of Stored Procedure

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 09:50 AM
Chandra
 
Posts: n/a
Default Re: Show All Months in First Column of Stored Procedure


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/
---------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 09:50 AM
jsfromynr
 
Posts: n/a
Default Re: Show All Months in First Column of Stored Procedure

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'
>From Orders,vwMonths Group by MonthName,Mon



With Warm regards
Jatinder Singh

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:35 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com