Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 rows become columns
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

3 Posts

Posted - 01/18/2007 :  08:05:17  Show Profile  Reply with Quote
hello all,
i am trying to create a view from a table that will keep track of the time between each stage of tasks given. take a look at the data below:

progressID taskID stage status theDate
1407525 1091657 In Progress Logged 2006-11-16 10:00:24.000
1407526 1091657 In Progress Inprogress 2006-11-16 12:08:59.036
1407214 1091657 In Progress Resolved 2006-11-16 14:15:48.000
1407220 1091657 Closed Solved 2006-11-16 14:36:05.000

i would like to be able to have just one row per task ID showing the difference between the stages, as shown below . only the 2nd column is a date, the rest are are hours (datediff) between the stage and its preceeding stage :

taskID Logged InProgress Resolved Solved
1091657 2006-11-16 10:00:24.000 2.08 2.07 0.21

is it possible to achieve such a transformation using views and a number of select statements (i.e no dts)? all assistance will be highly appreciated.



Patron Saint of Lost Yaks

30421 Posts

Posted - 01/18/2007 :  08:23:44  Show Profile  Visit SwePeso's Homepage  Reply with Quote
		CAST(DATEDIFF(minute, Logged, InProgress) / 60.0 AS NUMERIC(9, 2)) AS InProgress,
		CAST(DATEDIFF(minute, InProgress, Resolved) / 60.0 AS NUMERIC(9, 2)) AS Resolved,
		CAST(DATEDIFF(minute, Resolved, Solved) / 60.0 AS NUMERIC(9, 2)) AS Solved
			SELECT		TaskID,
					MAX(CASE WHEN Status = 'Logged' THEN theDate END) AS Logged,
					MAX(CASE WHEN Status = 'InProgress' THEN theDate END) AS InProgress,
					MAX(CASE WHEN Status = 'Resolved' THEN theDate END) AS Resolved,
					MAX(CASE WHEN Status = 'Solved' THEN theDate END) AS Solved
			FROM		YourTableNameHere
		) AS d

Peter Larsson
Helsingborg, Sweden

Edited by - SwePeso on 01/18/2007 08:26:00
Go to Top of Page

Starting Member

3 Posts

Posted - 01/18/2007 :  10:59:14  Show Profile  Reply with Quote
thanks for the help. much appreciated.

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000