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
 Help: WHERE Clause

Author  Topic 

JasonAnt
Starting Member

23 Posts

Posted - 2007-08-30 : 09:43:54
Header Table: SalesNo, Customer, SalesDate, etc
Detail Table: SalesNo, Item, Qty, UnitPrice

SELECT a.SalesNo, a.Customer, sum( b.Qty * b.UnitPrice ) as TotAmount
FROM tbHeader a inner join tbDetail b
ON tbHeader.SalesNo = tbDetail.SalesNo
WHERE a.SalesDate = '1/1/2000' and TotAmount > 1000
GROUP BY a.SalesNo, a.Customer

Cause Error, whats wrong ?
WHERE sum( b.Qty * b.UnitPrice ) > 1000 ..get same error

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-08-30 : 09:45:31
WHERE HAVING sum( b.Qty * b.UnitPrice ) > 1000


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

JasonAnt
Starting Member

23 Posts

Posted - 2007-08-30 : 09:53:52
Its work, thank you KhTan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-30 : 09:54:52
or

Select * from
(
SELECT a.SalesNo, a.Customer, sum( b.Qty * b.UnitPrice ) as TotAmount
FROM tbHeader a inner join tbDetail b
ON tbHeader.SalesNo = tbDetail.SalesNo
WHERE a.SalesDate = '1/1/2000'
GROUP BY a.SalesNo, a.Customer
) as T
where TotAmount > 1000

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -