Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
dougancil
Posting Yak Master
217 Posts |
Posted - 2011-01-10 : 15:29:15
|
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 scratchpad5SUM(CASE WHEN Cat=2 THEN [Minutes] ELSE 0 END) AS specminutesFROM(SELECT [EmployeeNumber],[Name],[Dateonly],[Minutes],1 AS CatFROM Scratchpad2where dateonly between '11/1/2010' and '11/8/2010'UNION ALLSELECT [EmployeeNumber],[Name],[ExceptionDate],[TotalMinutes],2FROM ScratchPad4)tGROUP BY [EmployeeNumber],[Name]and the syntax error I'm getting is:Server: Msg 170, Level 15, State 1, Line 2Line 2: Incorrect syntax near 'SUM'.Server: Msg 170, Level 15, State 1, Line 11Line 11: Incorrect syntax near 't'.Thank youDoug |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-01-10 : 15:39:17
|
[code]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 specminutesinto scratchpad5FROM(SELECT [EmployeeNumber],[Name],[Dateonly],[Minutes],1 AS CatFROM Scratchpad2where dateonly between '11/1/2010' and '11/8/2010'UNION ALLSELECT [EmployeeNumber],[Name],[ExceptionDate],[TotalMinutes],2FROM ScratchPad4)tGROUP BY [EmployeeNumber],[Name][/code]Everyday I learn something that somebody else already knew |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-01-10 : 15:40:33
|
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 specminutesJimEveryday I learn something that somebody else already knew |
|
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2011-01-10 : 15:42:40
|
Thanks Jim and Tara, I knew it was something simple. Must be a case of the "Mondays." |
|
|
|
|
|
|
|