September 23, 2014 at 7:11 am
Hi all,
Would like to do a quick question, when doing an arithmetic operation in select what is the correct way, see below examples, and why:
Select
SUM(Total) - SUM(sales)
--OR--
Select
SUM(Total-Sales)
Many thanks for any help provided
September 23, 2014 at 7:23 am
That really depends on what you're trying to achieve. Both could be correct (or incorrect).
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
September 23, 2014 at 7:25 am
Hi BWFC,
In what situations would you use them, that might help me.
Best regards,
Daniel
September 23, 2014 at 7:30 am
As previously mentioned either one can be correct. Those two calculations are NOT the same thing. A subtle difference perhaps but the results could vary greatly as they are calculating very different things.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 23, 2014 at 7:32 am
What Sean says.
It'll be much easier to suggest which to use if you can give us some sample data and tell us what you want to do with it.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply