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 - 2010-10-01 : 15:19:24
|
I have the following query:SELECT [Employees].name, [Employees].EmployeeNumber, dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440 +1 as date,dateadd(n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60/1440+1 AS Day, Sum([LoggedIn]/1000/60) AS LogIn, Sum ([OnTime]/1000/60) AS OnTime1,dateadd (n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1 AS Da INTO ScratchPad1FROM Employees INNER JOIN dbo.mOpInterval ON [Employees].Employeenumber = dbo.mOpInterval.OpnameGROUP BY [Employees].name, [Employees].EmployeeNumber, dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1,dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1,dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1 where dateadd (n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60))/1440+1, Between 9/15/2010 And 9/18/2010And when I try to run this I get the following error:Server: Msg 156, Level 15, State 1, Line 11Incorrect syntax near the keyword 'where'.Can anyone assist me with what I'm not seeing here? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-10-01 : 15:31:05
|
tara,Thank you and I've gone back and made some changes but it seems that the incorrect syntax is before the where clause:SELECT [Employees].name, [Employees].EmployeeNumber, dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440 +1 as date,dateadd(n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60/1440+1 AS Day, Sum([LoggedIn]/1000/60) AS LogIn, Sum ([OnTime]/1000/60) AS OnTime1,dateadd (n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1 AS Da INTO ScratchPad1FROM Employees INNER JOIN dbo.mOpInterval ON [Employees].Employeenumber = dbo.mOpInterval.OpnameGROUP BY [Employees].name, [Employees].EmployeeNumber, dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1,dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1,dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1 where dateadd ((n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60))/1440+1) Between '9/15/2010' And '9/18/2010'produces this error:Server: Msg 156, Level 15, State 1, Line 11Incorrect syntax near the keyword 'where'. |
|
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-10-01 : 15:31:06
|
tara,Thank you and I've gone back and made some changes but it seems that the incorrect syntax is before the where clause:SELECT [Employees].name, [Employees].EmployeeNumber, dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440 +1 as date,dateadd(n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60/1440+1 AS Day, Sum([LoggedIn]/1000/60) AS LogIn, Sum ([OnTime]/1000/60) AS OnTime1,dateadd (n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1 AS Da INTO ScratchPad1FROM Employees INNER JOIN dbo.mOpInterval ON [Employees].Employeenumber = dbo.mOpInterval.OpnameGROUP BY [Employees].name, [Employees].EmployeeNumber, dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1,dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1,dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1 where dateadd ((n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60))/1440+1) Between '9/15/2010' And '9/18/2010'produces this error:Server: Msg 156, Level 15, State 1, Line 11Incorrect syntax near the keyword 'where'. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-10-01 : 15:42:53
|
Tara,I'll let you know that if I run this without the where clause, this query produces results, just not in a specific date range but for all data within the database, so I know that the inner join works correctly as is (I believe) and I'll verify the number of parenthesis to make sure I don't have too many in there. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-10-01 : 16:29:09
|
Tara,Thanks for your help. This works now:SELECT [Employees].name, [Employees].EmployeeNumber, dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440 +1 as date,dateadd(n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60/1440+1 AS Day, Sum([LoggedIn]/1000/60) AS LogIn, Sum ([OnTime]/1000/60) AS OnTime1,dateadd (n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1 AS Da INTO ScratchPad1FROM Employees INNER JOIN dbo.mOpInterval ON [Employees].Employeenumber = dbo.mOpInterval.Opnamewhere dateadd (n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60/1440+1 Between '9/15/2010' And '9/18/2010'GROUP BY [Employees].name, [Employees].EmployeeNumber, dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1,dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1,dateadd(n,Timestamp, '12/31/1899')-([LoggedIn]/1000)/60/1440+1 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|