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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 HAVING SUM(WEIGHT)=SUM(HIGH)/2

Author  Topic 

nitsmooth
Yak Posting Veteran

68 Posts

Posted - 2009-11-05 : 11:46:44
HAVING SUM(WEIGHT)=SUM(HIGH)/2

why wont this work

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-11-05 : 12:00:54
As it is it won't work only because it is an incomplete statement.

Post the entire statement and explain what you mean by "won't...work". If there are errors post the error.



Be One with the Optimizer
TG
Go to Top of Page

nitsmooth
Yak Posting Veteran

68 Posts

Posted - 2009-11-05 : 12:07:58
incorrect syntax is the error
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-11-05 : 12:18:19
According to BOL:
quote:
The full syntax of the SELECT statement is complex, but the main clauses can be summarized as:

SELECT select_list

[ INTO new_table_name ]

FROM table_list

[ WHERE search_conditions ]

[ GROUP BY group_by_list ]

[ HAVING search_conditions ]

[ ORDER BY order_list [ ASC | DESC ] ]
As TG mentiuoned your statement is incomplete. If you care to provide more information we can help.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-11-05 : 12:23:51
here's an example of a complete statement that "works":

;with y (weight, high) as
(
select 10, 20 union all select 25,50 --union all select 1,1
)

select sum(weight) as totalweight, sum(high) as totalheight
from y
HAVING SUM(WEIGHT)=SUM(HIGH)/2

output:
totalweight totalheight
----------- -----------
35 70


Be One with the Optimizer
TG
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-11-05 : 12:35:56
Looks like you're missing a closing parenthises just before the RAISERROR

EDIT:

IF NOT EXISTS (
SELECT S.CALLID,SQ.QUESTION,SC.CATEGORY,SA.ANSWERDESC,SA.WEIGHT,SA.HIGH
FROM SURVEY S
JOIN SURVEY_RESPONSE SR
ON S.SURVEY_ID=SR.SURVEY_ID
JOIN SURVEY_QUESTION SQ
ON SQ.QUESTION_ID=SR.QUESTION_ID
JOIN SURVEY_CATEGORY SC
ON SC.CAT_ID=SQ.CAT_ID
JOIN SURVEY_ANSWER SA
ON SR.ANSWER_ID=SA.ANSWER_ID
WHERE (CONVERT(varchar(10), s.Submit_date, 101) = CONVERT(varchar(10), GETDATE()-1, 101))
GROUP BY S.CALLID,SQ.QUESTION,SC.CATEGORY,SA.ANSWERDESC,SA.WEIGHT,SA.HIGH
HAVING SUM(WEIGHT) < SUM(HIGH/2)
)
RAISERROR('no records found',16,1)


Be One with the Optimizer
TG
Go to Top of Page

nitsmooth
Yak Posting Veteran

68 Posts

Posted - 2009-11-05 : 12:39:41
Ya thts it!
Thanks
Go to Top of Page
   

- Advertisement -