Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorrect Syntax Error

Status
Not open for further replies.
Sep 10, 2009
37
US
I am getting an "incorrect syntax error" with the below code:

Having SUM(case when checkdate = dateadd(wk,-4, '2009-9-18') then d.units end) < 30
or
Having SUM(case when checkdate = dateadd(wk,-3, '2009-9-18') then d.units end) < 30
or
Having SUM(case when checkdate = dateadd(wk,-2, '2009-9-18') then d.units end) < 30
or
Having SUM(case when checkdate = dateadd(wk,-1, '2009-9-18') then d.units end) < 30

What I am trying to achieve is only return rows that have at least one less than 30 or a NULL value amount in the week column:

Week1 Week2 Week3 Week4
ALAN 30 40 38 40
ESTHER 16 50 50 50
HEDY 37 22 37 30
CLAUDIA 60 60 60 50
PENNY 60 60 60 NULL

Only these should display based on the having clauses I have above:

ESTHER 16 50 50 50
HEDY 37 22 37 30
PENNY 60 60 60 NULL


Thanks!!



 
Code:
.....
Having SUM(case when checkdate = dateadd(wk,-4, '2009-9-18') then d.units end) < 30
or
       SUM(case when checkdate = dateadd(wk,-3, '2009-9-18') then d.units end) < 30
or
       SUM(case when checkdate = dateadd(wk,-2, '2009-9-18') then d.units end) < 30
or
       SUM(case when checkdate = dateadd(wk,-1, '2009-9-18') then d.units end) < 30
You must have only ONE HAVING clause in the query.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top