Click here to Skip to main content
15,915,094 members
Home / Discussions / Database
   

Database

 
AnswerRe: urgent need max of second record..., Pin
Krish - KP21-Jun-07 18:48
Krish - KP21-Jun-07 18:48 
AnswerRe: urgent need max of second record..., Pin
Sathesh Sakthivel21-Jun-07 18:49
Sathesh Sakthivel21-Jun-07 18:49 
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 
Hi All,
1st off what is the best T-SQL book I can get for a novice? obviously I have much to learn.
If I run the query below as is I get this:

Msg 8120, Level 16, State 1, Line 12
Column 'job_ticket.LOCATION_ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Okay so I add it to the "group by" and it still does not work.
If I removed the piece in bold the query executes, but does not break down by "client".

Also the AVG should be the AVG of @startdate and @enddate; I know it's incorrect now but I cant get it to work the way I need it to.

I needed help to get where I am now....Thanks Roy


Table Job_ticket
Status_type_id varchar
Location_id varchar

Table Location
Location_ID varchar
Location_name varchar






SELECT Opened, [Total Open at Start], [Total Open at End],
[Total Open at End] - [Total Open at Start] as [Total Closed],
Client, [Average days open]
FROM (SELECT count(*) AS 'Opened',
SUM(CASE WHEN status_type_id LIKE '[1,2,6,7]'
THEN 1 ELSE 0
END) AS 'Total Open at Start',
(select count(*) from dbo.job_ticket as b
where j.location_id = b.location_id
and status_type_id like '[3,4,5]'
and last_updated between @startdate and @enddate)
AS 'Total Open at End',
l.location_name AS 'Client',
AVG(datediff(d,report_date,getdate() ))
AS [Average days open]
FROM job_ticket j
JOIN location l on l.location_id = j.location_id
WHERE (report_date BETWEEN @startdate AND @enddate)
GROUP BY l.location_name) as X



Regards,
Hulicat

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 
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 

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.