Click here to Skip to main content
15,909,445 members
Home / Discussions / Database
   

Database

 
AnswerRe: Audit Trail : Single table for all users or multiple table per user Pin
WoutL6-Mar-11 22:53
WoutL6-Mar-11 22:53 
AnswerRe: Audit Trail : Single table for all users or multiple table per user Pin
musefan6-Mar-11 22:57
musefan6-Mar-11 22:57 
GeneralRe: Audit Trail : Single table for all users or multiple table per user Pin
Dave Kerr6-Mar-11 23:03
mentorDave Kerr6-Mar-11 23:03 
GeneralRe: Audit Trail : Single table for all users or multiple table per user Pin
musefan6-Mar-11 23:36
musefan6-Mar-11 23:36 
AnswerRe: Audit Trail : Single table for all users or multiple table per user Pin
Eddy Vluggen7-Mar-11 0:15
professionalEddy Vluggen7-Mar-11 0:15 
AnswerRe: Audit Trail : Single table for all users or multiple table per user Pin
Wendelius7-Mar-11 1:52
mentorWendelius7-Mar-11 1:52 
QuestionUpgrading MSDE SP4 to SQL 2008 Express R2 Pin
Elsie6-Mar-11 19:46
Elsie6-Mar-11 19:46 
QuestionSQL Help - sum items based on max but also smaller than...? Pin
GlobX6-Mar-11 17:09
GlobX6-Mar-11 17:09 
Wow, not even sure how to word the question... Here goes:

Basically, I'm trying to build a custom burn-down with TFS, Excel and SQL. Don't ask me why I'm doing a custom one when I shouldn't be, that's a question for my boss Frown | :(

Anyhow, I have a query that's set up a few tables and now I want to join them. Here's an example of my two temp tables:

Tickets:
ID	Changed date		Points	State
61	2011-02-25 06:38:07.090	0	For Production
61	2011-02-26 03:46:02.577	0	In Production
61	2011-03-04 03:22:32.620	0	Done
499	2011-03-04 04:26:10.060	0	New
623	2011-02-28 00:25:45.250	0.5	In Production
708	2011-03-03 00:55:31.407	3	In Development
708	2011-03-03 00:57:27.497	3	In Development
708	2011-03-03 03:55:17.390	3	In QA/UAT
708	2011-03-03 23:05:56.020	3	In QA/UAT
708	2011-03-04 05:21:43.133	3	In QA/UAT
738	2011-02-28 05:04:04.250	5	In Development
738	2011-02-28 22:56:58.053	5	In Development
738	2011-03-01 00:50:28.037	5	In Development
738	2011-03-01 21:06:35.550	5	In Development
738	2011-03-03 22:54:17.137	5	In QA/UAT
894	2011-02-28 00:29:04.183	0	To Do


Historical data in TFS is stored as a copy of the WorkItem row as it was BEFORE the change, along with a Changed Date field. In other words, the work item with id 3 has multiple copies in the WorkItemsWere table, each with a set of different properties, as can be seen above.

and Sprint Days:
Day	Day of year
Mon 1	51
Tue 1	52
Wed 1	53
Thu 1	54
Fri 1	55
Mon 2	58
Tue 2	59
Wed 2	60
Thu 2	61
Fri 2	62


I am achieving my burn-down by joining these two tables. My results so far look like this:

Day	Points  Day of year
Mon 1	0	51
Tue 1	0	52
Wed 1	0	53
Thu 1	0	54
Fri 1	0	55
Mon 2	0	58
Tue 2	0	59
Tue 2	5	59
Wed 2	0	60
Wed 2	10	60
Thu 2	0	61
Thu 2	10	61
Fri 2	0	62
Fri 2	3	62
Fri 2	15	62


See, the problem is I am joining each row in my sprint days table against EVERY work item row with a changed date <= the sprint day, and then summing. Here's my query:

SELECT
	[Day] AS [Sprint Day],
	SUM(Points) AS Points,
	[Day of year] AS [Order]
	
FROM
	#sprintDays d
	
	LEFT JOIN
		(
			SELECT
				Id,
				Points,
				DATEPART(DAYOFYEAR, [Changed Date]) AS [Changed Date],
				ROW_NUMBER() OVER
				(
					PARTITION BY
						Id,
						DATEPART(DAYOFYEAR, [Changed Date])
					ORDER BY
						DATEPART(DAYOFYEAR, [Changed Date]) DESC
				) AS Row
				
			FROM
				#tickets

			WHERE
				([State] = 'Committed' OR
				 [State] = 'In Development' OR
				 [State] = 'In QA/UAT')
				 
			UNION
			
			SELECT                     -- this is to ensure that something 
				0,                 -- comes out for any given day
				0,
				0,
				1
				
		) AS t
	ON d.[Day of year] <= t.[Changed Date] -- this is the dodgy bit here, methinks
		
GROUP BY
	t.Row,
	t.Id,
	[Day],
	[Day of year]

HAVING
	Row = 1

ORDER BY
	[Order] ASC


What I REALLY need to do, is join against something like MAX(ChangedDate) WHERE ChangedDate <= SprintDay, i.e. the sum of the points of each row in #tickets that has both the highest (latest) ChangedDate and also has a ChangedDate that is smaller than the [Day of year] of the SprintDay row I am joining to.

Does that make any sense? Apologies if it doesn't, my brain is melting ever-so-slightly...
AnswerRe: SQL Help - sum items based on max but also smaller than...? Pin
Wendelius7-Mar-11 7:40
mentorWendelius7-Mar-11 7:40 
GeneralRe: SQL Help - sum items based on max but also smaller than...? [modified] Pin
GlobX7-Mar-11 12:12
GlobX7-Mar-11 12:12 
GeneralRe: SQL Help - sum items based on max but also smaller than...? Pin
Wendelius7-Mar-11 18:37
mentorWendelius7-Mar-11 18:37 
AnswerRe: SQL Help - sum items based on max but also smaller than...? Pin
GlobX7-Mar-11 13:05
GlobX7-Mar-11 13:05 
Questioncopy data from 1 table to another table Pin
bapu28895-Mar-11 6:07
bapu28895-Mar-11 6:07 
AnswerRe: copy data from 1 table to another table Pin
Mycroft Holmes5-Mar-11 12:07
professionalMycroft Holmes5-Mar-11 12:07 
AnswerRe: copy data from 1 table to another table Pin
PIEBALDconsult5-Mar-11 14:48
mvePIEBALDconsult5-Mar-11 14:48 
QuestionRe: copy data from 1 table to another table Pin
bapu28895-Mar-11 19:57
bapu28895-Mar-11 19:57 
QuestionRead only ADO connection still allows writing to database? Pin
PJ Arends4-Mar-11 17:54
professionalPJ Arends4-Mar-11 17:54 
AnswerRe: Read only ADO connection still allows writing to database? Pin
Mycroft Holmes4-Mar-11 19:59
professionalMycroft Holmes4-Mar-11 19:59 
GeneralRe: Read only ADO connection still allows writing to database? Pin
PJ Arends6-Mar-11 10:26
professionalPJ Arends6-Mar-11 10:26 
GeneralRe: Read only ADO connection still allows writing to database? Pin
Mycroft Holmes6-Mar-11 11:42
professionalMycroft Holmes6-Mar-11 11:42 
GeneralRe: Read only ADO connection still allows writing to database? Pin
PJ Arends6-Mar-11 17:51
professionalPJ Arends6-Mar-11 17:51 
GeneralRe: Read only ADO connection still allows writing to database? Pin
Mycroft Holmes6-Mar-11 18:01
professionalMycroft Holmes6-Mar-11 18:01 
QuestionUpdating Columns Pin
whatsa3-Mar-11 14:14
whatsa3-Mar-11 14:14 
AnswerRe: Updating Columns Pin
Luc Pattyn3-Mar-11 14:24
sitebuilderLuc Pattyn3-Mar-11 14:24 
GeneralRe: Updating Columns Pin
whatsa17-Mar-11 10:07
whatsa17-Mar-11 10:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.