# SUM and Addition of Null

• π Simply Nice.

(note: aliasing the columns in the first select statement will be enough)

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

• Really Nice !

Simple and Best. π

(Truth is Higher, Still Higher is Truthful Living)

If I Stop Learning, I Cease to Be A SIKH !

• Nice question to start week with +1 π

_______________________________________________________________
http://www.sqlservercentral.com/articles/Best+Practices/61537/

• Easy one for the Monday π

Especially easy because the way the answers were structured, you only had to calculate the last column π

Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP

• Excellent question, thanks very much. Have a good week.

---

Note to developers:
CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

My blog: http://uksqldba.blogspot.com
Visit http://www.DerekColley.co.uk to find out more about me.

• Nice & Easy one..

Thanks

• Remember that SUM may return NULL, so SUM(num1)+SUM(num2) may lead to NULL:

`select`

` sum(num1) AS S1,`

` sum(num2) AS S2,`

` sum(num1) + sum(num2) AS S3,`

` sum(num1 + num2) AS S4`

` from`

` (`

` select cast('1' as int) as num1, cast(NULL as int) as num2`

` union all`

` select '1' as num1, NULL as num2`

` union all`

` select '1' as num1, NULL as num2`

` union all`

` select NULL as num1, NULL as num2`

` ) as t`

The above select return 3,NULL,NULL,NULL

• Thanks for an easy start to the week

-------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. β Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx

• good one Carlo

_______________________________________________________________
http://www.sqlservercentral.com/articles/Best+Practices/61537/

• Thanks for the nice start to the week!

• Easy and interesting question.Ta.

βWhen I hear somebody sigh, βLife is hard,β I am always tempted to ask, βCompared to what?ββ - Sydney Harris

• Nice and easy question.

Back to basics, really, but quite a few basics: aggregates, aggregates' handling of nulls, arithmetic operations handling of nulls, and implicit type conversion (as well as simple arithemetic) :-).

Tom

• Cheers for something easy on a Monday! :satisfied:

Aigle de Guerre!

• easy π thanks

Viewing 15 posts - 1 through 15 (of 19 total)