Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi,I have a query with DISTINCT option. If i use DISTINCT option with aggregate function like SUM will it eliminate duplicate values and then sum the values of a column and what is the syntax for it.EX I have a column for budgetBUDGET100350275350100so if i use DISTINCT SUM(BUDGET) will it eliminate duplicate values and sum the total.
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2007-12-14 : 16:25:44
No, maybe an example would help:
DECLARE @Budget TABLE (Budget MONEY)INSERT @BudgetSELECT 100UNION ALL SELECT 350UNION ALL SELECT 275UNION ALL SELECT 350UNION ALL SELECT 100SELECT DISTINCT SUM(Budget)FROM @BudgetSELECT SUM(DISTINCT Budget)FROM @Budget