| Author |
Topic  |
|
|
CoffeeAddict
Yak Posting Veteran
94 Posts |
Posted - 09/26/2012 : 23:09:22
|
I'm trying to sum these 2 fields up. I don't know if I should do just Sum(firstField) + Sum(SecondField) or Sum(FirstField + SecondField) but I can't get it to work regardless due to syntax errors:
select CarCondemned.CarKey, SUM(CarCondemned.Head + carsheet.UserFld2) AS AUPU from CarCondemned CarCondemned join CarSheet carsheet on carsheet.CarKey = CarCondemned.CarKey where CarCondemned.CauseCode = 80 group by CarCondemned.CarKey
Head is type int and UserFld2 is type decimal(13,5)
|
Edited by - CoffeeAddict on 09/27/2012 00:10:43
|
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8515 Posts |
Posted - 09/27/2012 : 02:52:07
|
can you post the error message please?
Too old to Rock'n'Roll too young to die. |
 |
|
|
sql-programmers
Posting Yak Master
USA
189 Posts |
Posted - 09/27/2012 : 06:00:55
|
Sum(firstField) + Sum(SecondField) or Sum(FirstField + SecondField)
Both result will be same we don't bother about that But If any one filed is NULLABLE in BOTH fields, We need to write query like ISNULL(Sum(firstField), 0) + ISNULL(Sum(SecondField), 0) or Sum(ISNULL(FirstField, 0) + ISNULL(SecondField, 0))
In the both method , I think Sum(ISNULL(FirstField, 0) + ISNULL(SecondField, 0)) method more sufficient.
Can you post error message?
I think your query is write. but i dont know why it gives error.
Solution: change your alias name of the Table and execute the query
SQL Server Programmers and Consultants http://www.sql-programmers.com/ |
Edited by - sql-programmers on 09/27/2012 06:02:58 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47189 Posts |
Posted - 09/27/2012 : 10:32:24
|
Op has not shown full query so it might be that error is caused by some other portion. But for that we atleast need to see the error message
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|