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 2005 Forums
 Transact-SQL (2005)
 table transpose

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2007-11-19 : 16:23:20

The sql ret is in t1.
date col1 col2
11/1/07 2 3
11/2/07
11/5/07
11/6/07
11/7/07
11/8/07
11/9/07
11/12/07
----
11/19/07

I want tranpose it to t2
date 11/1/07 11/2/07 11/5/07 11/6/07 11/7/07 11/8/07 11/9/07-11/12/07
Q1 2
Q2 3

The date does not include weekends. I need to run it every day so the records in t1 keep on increasing by 1 every weekday.
How can I do it? I have sql query anlyzer 2000
Thanks

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-19 : 18:47:59
create the linked procedure and you can use that to simulate a PIVOT function in SQL 2000 (Pivot available in SQL 2005, but you indicate SQL 2000)

If your SQL server is a 2005 box, look at the PIVOT function in BOL for SQL 2005.
http://media.techtarget.com/digitalguide/images/Misc/sp_Crosstab.txt



Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-20 : 01:35:18
Also if you want to present your data in reports, make use of it's cross-tab feature

Madhivanan

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

jeff06
Posting Yak Master

166 Posts

Posted - 2007-11-20 : 08:08:51
Thanks,
The trouble is I do not have right to create a precdure in the query analyzer.
Is there a solution to that?
Jeff
Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-11-20 : 08:26:42
My table also have a id colume, thanks
The sql ret is in t1.
id date col1 col2
1 11/1/07 2 3
2 11/2/07
3 11/5/07
4 11/6/07
5 11/7/07
6 11/8/07
7 11/9/07
8 11/12/07
----
20 11/19/07

I want tranpose it to t2
id 1 2 3 4 5 6 7 ---------------- 20
date 11/1/07 11/2/07 11/5/07 11/6/07 11/7/07 11/8/07 11/9/07-11/12/07
Q1 2
Q2 3
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-20 : 08:29:19
you posted in a SQL Server 2005 forum but you state "I have sql query anlyzer 2000".

If you are using SQL Server 2005, use the PIVOT function to do it.


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

Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-11-20 : 08:49:55
Sorry I never realized sql server 2000 and 2005 are in different forum.
I have started a new thread in sql server 2000 and I do not know how to delete this thread.
Thanks
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-20 : 08:57:46
you can't delete it once there are replies to the thread


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

Go to Top of Page
   

- Advertisement -