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
 General SQL Server Forums
 New to SQL Server Programming
 SP to display selected dates as columns

Author  Topic 

sradez
Starting Member

6 Posts

Posted - 2007-07-31 : 16:11:47

Hi all,
i have a table which has date and count as column
Can you please...help me write a query for it.

date | type | count
10/07 | A | 70
11/07 | A | 50
12/07 | A | 50
11/07 | B | 60
12/07 | B | 50
13/07 | B | 40
11/07 | C | 50
12/07 | C | 60
13/07 | C |60
14/07 | A | 50
i need to write a sp such that..if user sends date and @ndays(no. of days) as parameter say 11/07 and 3

then

out put

type 11/07 12/07 13/07
A 50 50
B 60 50 40
C 50 60 60


Thanks..

Regards,
sradez

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-31 : 16:17:08
search for pivot here

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-01 : 02:31:36
or read about Cross-tab reports in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-01 : 02:34:26
How many column will there ever be at maximum? 31? One month?

If so, make the sp static and not dynamic! Always return 31 days numbered 1-31 and hide the columns you don't want in the front-end application and rename the headers.




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -