| Author |
Topic  |
|
|
dougancil
Posting Yak Master
USA
217 Posts |
Posted - 10/01/2010 : 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 ScratchPad1
FROM Employees INNER JOIN dbo.mOpInterval ON [Employees].Employeenumber = dbo.mOpInterval.Opname
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
where dateadd (n,Timestamp,'12/31/1899')-([LoggedIn]/1000)/60))/1440+1, Between 9/15/2010 And 9/18/2010
And when I try to run this I get the following error: Server: Msg 156, Level 15, State 1, Line 11 Incorrect syntax near the keyword 'where'.
Can anyone assist me with what I'm not seeing here?
|
|
|
tkizer
Almighty SQL Goddess
USA
35007 Posts |
|
|
dougancil
Posting Yak Master
USA
217 Posts |
Posted - 10/01/2010 : 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 ScratchPad1
FROM Employees INNER JOIN dbo.mOpInterval ON [Employees].Employeenumber = dbo.mOpInterval.Opname
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
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 11 Incorrect syntax near the keyword 'where'.
|
 |
|
|
dougancil
Posting Yak Master
USA
217 Posts |
Posted - 10/01/2010 : 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 ScratchPad1
FROM Employees INNER JOIN dbo.mOpInterval ON [Employees].Employeenumber = dbo.mOpInterval.Opname
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
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 11 Incorrect syntax near the keyword 'where'.
|
 |
|
|
tkizer
Almighty SQL Goddess
USA
35007 Posts |
|
|
dougancil
Posting Yak Master
USA
217 Posts |
Posted - 10/01/2010 : 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
USA
35007 Posts |
|
|
dougancil
Posting Yak Master
USA
217 Posts |
Posted - 10/01/2010 : 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 ScratchPad1
FROM Employees INNER JOIN dbo.mOpInterval ON [Employees].Employeenumber = dbo.mOpInterval.Opname
where 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
USA
35007 Posts |
|
| |
Topic  |
|
|
|