Discussion:
Incorrect syntax near the keyword 'End'.
(too old to reply)
Betty
2006-09-04 12:29:25 UTC
Permalink
Afternoon,

I am having trouble with the following code due to a syntax error near
'End'. But i cannot see why it has an error.

The code should display in two separate columns the total amount of
'Leads' raised by Joe Bloggs.

Code as follows...

SELECT AWD.EmpName, IsNull(FirstMonth.Leads,0) as FirstMonthLeads,
IsNull(SecondMonth.Leads,0) as SecondMonthLeads
From AgentworkDetail AWD
Left Outer Join (
select EmpName,
Case (IsNull(Sum(Leads),0)) End as Leads
from AgentWorkDetail
Where Timesheetdate between
Case When month(current_timestamp)=9 Then '20060701' End
and
Case When month(current_timestamp)=9 Then '20060731' End
group by EmpName
) as FirstMonth on Firstmonth.EmpName = AWD.EmpName

Left Outer Join (
select EmpName,
Case (IsNull(Sum(Leads),0)) End as Leads
from AgentWorkDetail
Where Timesheetdate between
Case When month(current_timestamp)=9 Then '20060801' End
and
Case When month(current_timestamp)=9 Then '20060831' End
group by EmpName
) as SecondMonth on Secondmonth.EmpName = AWD.EmpName

Where AWD.empname = 'Joe Bloggs'
group by AWD.EmpName, FirstMonth.Leads, SecondMonth.Leads



Can anyone help?
Martin Poon [MVP]
2006-09-04 12:35:56 UTC
Permalink
Case (IsNull(Sum(Leads),0)) End as Leads

should be (or something similar to)

IsNull(Sum(Leads),0) End as Leads
--
Martin Poon
Microsoft MVP - SQL Server
====================================
Post by Betty
Afternoon,
I am having trouble with the following code due to a syntax error near
'End'. But i cannot see why it has an error.
The code should display in two separate columns the total amount of
'Leads' raised by Joe Bloggs.
Code as follows...
SELECT AWD.EmpName, IsNull(FirstMonth.Leads,0) as FirstMonthLeads,
IsNull(SecondMonth.Leads,0) as SecondMonthLeads
From AgentworkDetail AWD
Left Outer Join (
select EmpName,
Case (IsNull(Sum(Leads),0)) End as Leads
from AgentWorkDetail
Where Timesheetdate between
Case When month(current_timestamp)=9 Then '20060701' End
and
Case When month(current_timestamp)=9 Then '20060731' End
group by EmpName
) as FirstMonth on Firstmonth.EmpName = AWD.EmpName
Left Outer Join (
select EmpName,
Case (IsNull(Sum(Leads),0)) End as Leads
from AgentWorkDetail
Where Timesheetdate between
Case When month(current_timestamp)=9 Then '20060801' End
and
Case When month(current_timestamp)=9 Then '20060831' End
group by EmpName
) as SecondMonth on Secondmonth.EmpName = AWD.EmpName
Where AWD.empname = 'Joe Bloggs'
group by AWD.EmpName, FirstMonth.Leads, SecondMonth.Leads
Can anyone help?
Betty
2006-09-04 13:15:05 UTC
Permalink
Cheers Martin,

This is now working fine.


Regards
Betty

Jens
2006-09-04 12:45:15 UTC
Permalink
As I understand your query right, you don“t need the CASE expression
for this:

IsNull(Sum(Leads),0) As Leads

CASE would expect a comparison and a THEN part.

HTH, Jens Suessmeyer

---
http://www.sqlserver2005.de
---
Betty
2006-09-04 13:13:51 UTC
Permalink
Many Thanks Jens, this is now working.


Kind Regards
Betty
Loading...