Click here to Skip to main content
15,908,013 members
Home / Discussions / Database
   

Database

 
GeneralRe: urgent need max of second record..., Pin
Member 387988121-Jun-07 19:50
Member 387988121-Jun-07 19:50 
Answeryour right answer is here Pin
Sylvester george21-Jun-07 20:37
Sylvester george21-Jun-07 20:37 
QuestionSyntax Error in INSERT INTO Statement Pin
Cfer8321-Jun-07 6:08
Cfer8321-Jun-07 6:08 
QuestionRe: Syntax Error in INSERT INTO Statement Pin
Cfer8322-Jun-07 4:17
Cfer8322-Jun-07 4:17 
AnswerRe: Syntax Error in INSERT INTO Statement Pin
sidbaruah27-Jun-07 22:48
sidbaruah27-Jun-07 22:48 
QuestionDying on this query Pin
Hulicat21-Jun-07 4:16
Hulicat21-Jun-07 4:16 
AnswerRe: Dying on this query Pin
Krish - KP21-Jun-07 5:08
Krish - KP21-Jun-07 5:08 
AnswerRe: Dying on this query Pin
andyharman21-Jun-07 5:19
professionalandyharman21-Jun-07 5:19 
I think what you're after is:
SELECT L.location_name AS Client,
   TotalOpenAtStart,
   TotalOpenAtEnd,
   (TotalOpenAtEnd - TotalOpenAtEnd) AS TotalClosed,
   AvgDaysOpen
FROM location l
LEFT OUTER JOIN (
   SELECT j.location_id,
      SUM(CASE WHEN j.status_type_id IN (1,2,6,7) THEN 1 ELSE 0 END) AS TotalOpenAtStart,
      SUM(CASE WHEN j.status_type_id IN (3,4,5) THEN 1 ELSE 0 END) AS TotalOpenAtEnd,
      AVG(DATEDIFF(d, j.report_date, GETDATE())) AS AvgDaysOpen
   FROM job_ticket j
   WHERE j.report_date BETWEEN @startdate AND @enddate)
   GROUP BY j.location_id
) x
ON x.location_id = l.location_id
ORDER BY L.location_name
Regards
Andy
GeneralRe: Dying on this query Pin
Hulicat21-Jun-07 6:13
Hulicat21-Jun-07 6:13 
GeneralRe: Dying on this query Pin
andyharman22-Jun-07 0:40
professionalandyharman22-Jun-07 0:40 
GeneralRe: Dying on this query Pin
Hulicat22-Jun-07 2:02
Hulicat22-Jun-07 2:02 
AnswerRe: Dying on this query Pin
Michael Potter21-Jun-07 10:52
Michael Potter21-Jun-07 10:52 
GeneralRe: Dying on this query Pin
Hulicat21-Jun-07 13:23
Hulicat21-Jun-07 13:23 
GeneralRe: Dying on this query Pin
Michael Potter22-Jun-07 3:05
Michael Potter22-Jun-07 3:05 
GeneralRe: Dying on this query Pin
Hulicat22-Jun-07 16:06
Hulicat22-Jun-07 16:06 
QuestionProblem with special characters in SqlParameter Pin
chovdry21-Jun-07 4:10
chovdry21-Jun-07 4:10 
AnswerRe: Problem with special characters in SqlParameter Pin
Colin Angus Mackay21-Jun-07 4:41
Colin Angus Mackay21-Jun-07 4:41 
GeneralRe: Problem with special characters in SqlParameter Pin
chovdry21-Jun-07 5:02
chovdry21-Jun-07 5:02 
GeneralRe: Problem with special characters in SqlParameter Pin
Mike Dimmick21-Jun-07 5:49
Mike Dimmick21-Jun-07 5:49 
AnswerRe: Problem with special characters in SqlParameter Pin
Krish - KP21-Jun-07 5:20
Krish - KP21-Jun-07 5:20 
GeneralRe: Problem with special characters in SqlParameter Pin
Mike Dimmick21-Jun-07 5:38
Mike Dimmick21-Jun-07 5:38 
GeneralRe: Problem with special characters in SqlParameter Pin
Krish - KP21-Jun-07 6:01
Krish - KP21-Jun-07 6:01 
QuestionFormula Pin
ScottM121-Jun-07 2:01
ScottM121-Jun-07 2:01 
AnswerRe: Formula Pin
Colin Angus Mackay21-Jun-07 2:18
Colin Angus Mackay21-Jun-07 2:18 
GeneralRe: Formula Pin
ScottM121-Jun-07 2:42
ScottM121-Jun-07 2:42 

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.