SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Syntax Error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dougancil
Posting Yak Master

USA
217 Posts

Posted - 01/10/2011 :  15:29:15  Show Profile  Send dougancil a Yahoo! Message  Reply with Quote
I have the following query that I'm trying to run but I'm having a syntax issue. I know that it's something simple that I'm missing so any help would be appreciated. The query is:

SELECT [EmployeeNumber],[Name],SUM([Minutes]) AS summinutes,SUM([Minutes])/60 AS sumhours into scratchpad5
SUM(CASE WHEN Cat=2 THEN [Minutes] ELSE 0 END) AS specminutes
FROM
(
SELECT [EmployeeNumber],[Name],[Dateonly],[Minutes],1 AS Cat
FROM Scratchpad2
where dateonly between '11/1/2010' and '11/8/2010'
UNION ALL
SELECT [EmployeeNumber],[Name],[ExceptionDate],[TotalMinutes],2
FROM ScratchPad4
)t
GROUP BY [EmployeeNumber],[Name]

and the syntax error I'm getting is:

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'SUM'.
Server: Msg 170, Level 15, State 1, Line 11
Line 11: Incorrect syntax near 't'.

Thank you

Doug

tkizer
Almighty SQL Goddess

USA
36932 Posts

Posted - 01/10/2011 :  15:38:36  Show Profile  Visit tkizer's Homepage  Reply with Quote
Well you've got "into scratchpad5" and then another SUM. You can't do that. INTO must come directly before the FROM.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 01/10/2011 :  15:39:17  Show Profile  Reply with Quote

SELECT [EmployeeNumber],[Name],SUM([Minutes]) AS summinutes,SUM([Minutes])/60 AS sumhours  into scratchpad5 
SUM(CASE WHEN Cat=2 THEN [Minutes] ELSE 0 END) AS specminutes

into scratchpad5
FROM
(
SELECT [EmployeeNumber],[Name],[Dateonly],[Minutes],1 AS Cat
FROM Scratchpad2
where dateonly between '11/1/2010' and '11/8/2010'
UNION ALL
SELECT [EmployeeNumber],[Name],[ExceptionDate],[TotalMinutes],2
FROM ScratchPad4
)t
GROUP BY [EmployeeNumber],[Name]



Everyday I learn something that somebody else already knew
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 01/10/2011 :  15:40:33  Show Profile  Reply with Quote
Oops, hit send instead of preview. You'll also need a comma before last sum
,SUM(CASE WHEN Cat=2 THEN [Minutes] ELSE 0 END) AS specminutes


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

dougancil
Posting Yak Master

USA
217 Posts

Posted - 01/10/2011 :  15:42:40  Show Profile  Send dougancil a Yahoo! Message  Reply with Quote
Thanks Jim and Tara, I knew it was something simple. Must be a case of the "Mondays."
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.11 seconds. Powered By: Snitz Forums 2000