Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pivoting data into a table

Status
Not open for further replies.

moleboy

IS-IT--Management
Oct 10, 2002
33
GB
I'm trying to manipulate some data into a table.

the results of the query are

date 9:00 10:00 11:00 12:00
1/09/03 0 2 7 4
2/09/03 1 5 9 15

and I neesd to insert into

date timeslot Value
1/09/03 9:00 0
1/09/03 10:00 2
1/09/03 11:00 7
1/09/03 12:00 4
2/09/03 9:00 1
etc


my code to get the date looks like

SELECT date,
SUM(CASE
WHEN [start] <= '09:00' And [end]> '09:29'THEN 1 ELSE 0 END) AS [09:00],
SUM(CASE
WHEN [start] <= '10:00' And [end]> '10:29'THEN 1 ELSE 0 END) AS [10:00],
SUM(CASE
WHEN [start] <= '11:00' And [end]>'11:29' THEN 1 ELSE 0 END) AS [11:00],
FROM aTAble

Any ideas on how to pivot the data within an insert??????????
 
moleboy,

Sorry, I'm obvioudly not getting the full question here.

From your question you appear to be using a Pivoting query to get results that you then want to pivot back again and insert it into a table.

What does the original data source data like? My reasons for asking is that maybe you could use a standard query to get the data and it will be in the format required.

Logicalman.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top