Click here to Skip to main content
15,913,941 members
Home / Discussions / Database
   

Database

 
AnswerRe: Remote access problem - sql server2008- Out of Domain Pin
Byron70705-Aug-09 16:37
Byron70705-Aug-09 16:37 
GeneralRe: Remote access problem - sql server2008- Out of Domain Pin
Paramu19735-Aug-09 23:21
Paramu19735-Aug-09 23:21 
GeneralRe: Remote access problem - sql server2008- Out of Domain Pin
Byron70706-Aug-09 6:48
Byron70706-Aug-09 6:48 
AnswerRe: Remote access problem - sql server2008- Out of Domain Pin
Aman786Singh7-Aug-09 2:44
Aman786Singh7-Aug-09 2:44 
QuestionTo fetch the data from different tables Pin
srikantha_nagaraj5-Aug-09 3:45
srikantha_nagaraj5-Aug-09 3:45 
AnswerRe: To fetch the data from different tables Pin
Mycroft Holmes5-Aug-09 22:13
professionalMycroft Holmes5-Aug-09 22:13 
AnswerRe: To fetch the data from different tables Pin
Kschuler7-Aug-09 9:48
Kschuler7-Aug-09 9:48 
Questionstop select case creating new rows? Pin
Tommy Pickersgill5-Aug-09 2:33
Tommy Pickersgill5-Aug-09 2:33 
I've created a stored procedure which retrives a list of worklogs for a specific week, log time is added together, joined to user table based on UserID and then returned as HoursWorked.

This worked fine as the following code:

ALTER procedure [dbo].[GetAllUsersWhoHaventSubmittedTimeForWeek]
(
@MinimumHours float,
@EndDate datetime,
@AmountOfDaysBack int
)
as
begin
SELECT u.Email, u.FirstName + ' ' + u.LastName AS Usersname, round(sum(WorkDone) / 60, 1)
FROM Users u LEFT OUTER JOIN 
(
	select sum(WorkDone) WorkDone, UserId UserId, WorkUnitTypeId WorkUnitTypeId
	FROM worklog
	WHERE WorkLogDateTime >= dateadd(d, -@AmountOfDaysBack, @EndDate) and WorkLogDateTime <= dateadd(d, 1, @EndDate)
	GROUP BY UserID, WorkUnitTypeId
	HAVING round(sum(WorkDone) / 60, 1) < @MinimumHours
) w
ON u.UserId=w.UserId
WHERE u.userid not in (SELECT User_ID FROM ReportUsers WHERE Status = 0) and u.isactive = 1
GROUP BY w.UserId, u.FirstName, u.LastName, u.Email, WorkUnitTypeId
ORDER BY sum(WorkDone) DESC

END



I then realised WorkDone can sometimes store hours, days or weeks and is defined in 'WorkUnitTypeID' so I added a CASE statement to the Select:

ALTER procedure [dbo].[GetAllUsersWhoHaventSubmittedTimeForWeek]
(
@MinimumHours float,
@EndDate datetime,
@AmountOfDaysBack int
)
as
begin
SELECT u.Email, u.FirstName + ' ' + u.LastName AS Usersname,
	CASE w.WorkUnitTypeId
		WHEN 1 THEN ISNULL(round(sum(w.WorkDone / 60),1), 0) --Minutes
		WHEN 2 THEN ISNULL(round(sum(w.WorkDone),1), 0)		 --Hours
		WHEN 3 THEN ISNULL(round(sum(w.WorkDone * 24),1), 0) --Days
		WHEN 4 THEN ISNULL(round(sum(w.WorkDone * 168),1), 0) --Weeks
		ELSE 0
	END WorkDone
FROM Users u LEFT OUTER JOIN 
(
	select sum(WorkDone) WorkDone, UserId UserId, WorkUnitTypeId WorkUnitTypeId
	FROM worklog
	WHERE WorkLogDateTime >= dateadd(d, -@AmountOfDaysBack, @EndDate) and WorkLogDateTime <= dateadd(d, 1, @EndDate)
	GROUP BY UserID, WorkUnitTypeId
	HAVING round(sum(WorkDone) / 60, 1) < @MinimumHours
) w
ON u.UserId=w.UserId
WHERE u.userid not in (SELECT User_ID FROM ReportUsers WHERE Status = 0) and u.isactive = 1
GROUP BY w.UserId, u.FirstName, u.LastName, u.Email, WorkUnitTypeId
ORDER BY sum(WorkDone) DESC

END


Again this worked but presented a new issue, the procedure now returns multiple rows for the same user but for each of the WorkUnitTypeID - instead of adding them together.

I'm new to SQL in general and have that feeling I've missed something really simple! Any feedback would be much appreciated.

Tommy
AnswerRe: stop select case creating new rows? Pin
WoutL5-Aug-09 3:29
WoutL5-Aug-09 3:29 
GeneralRe: stop select case creating new rows? Pin
Tommy Pickersgill5-Aug-09 3:51
Tommy Pickersgill5-Aug-09 3:51 
GeneralRe: stop select case creating new rows? Pin
WoutL5-Aug-09 9:25
WoutL5-Aug-09 9:25 
AnswerRe: stop select case creating new rows? Pin
Tommy Pickersgill5-Aug-09 6:46
Tommy Pickersgill5-Aug-09 6:46 
GeneralRe: stop select case creating new rows? Pin
i.j.russell5-Aug-09 11:39
i.j.russell5-Aug-09 11:39 
GeneralRe: stop select case creating new rows? [modified] Pin
Tommy Pickersgill5-Aug-09 23:06
Tommy Pickersgill5-Aug-09 23:06 
QuestionDesigning Table to Record Hierarchy Pin
vhassan5-Aug-09 0:58
vhassan5-Aug-09 0:58 
QuestionSQL Server config Pin
helelark1234-Aug-09 6:13
helelark1234-Aug-09 6:13 
AnswerRe: SQL Server config Pin
leckey4-Aug-09 16:02
leckey4-Aug-09 16:02 
GeneralRe: SQL Server config Pin
helelark1234-Aug-09 18:44
helelark1234-Aug-09 18:44 
AnswerRe: SQL Server config Pin
N a v a n e e t h4-Aug-09 17:52
N a v a n e e t h4-Aug-09 17:52 
GeneralRe: SQL Server config Pin
helelark1234-Aug-09 18:46
helelark1234-Aug-09 18:46 
QuestionThe ORA-01033: ORACLE initialization or shutdown in progress Pin
vikash_singh4-Aug-09 5:59
vikash_singh4-Aug-09 5:59 
AnswerRe: The ORA-01033: ORACLE initialization or shutdown in progress Pin
suresh.palghar1-Sep-09 23:31
suresh.palghar1-Sep-09 23:31 
QuestionLoading(Importing) Data into SQL Server 2005 Pin
sm_sadhik4-Aug-09 5:00
sm_sadhik4-Aug-09 5:00 
AnswerRe: Loading(Importing) Data into SQL Server 2005 Pin
i.j.russell5-Aug-09 11:42
i.j.russell5-Aug-09 11:42 
QuestionInvalid column name error? Pin
cdietschrun4-Aug-09 4:25
cdietschrun4-Aug-09 4:25 

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.