Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Typed NULL and non-typed NULL

Aug 2 2012 12:00AM by Madhivanan   

I have posted a question for July 2012 at Question of the month July 2012 - How does COALESCE(null,null+1,null) work? Did you know why the second query works without any error?

A NULL value can be of two types. Typed NULL and non-Typed NULL.

SELECT SUM(NULL)
will throw the error
Msg 8117, Level 16, State 1, Line 2
Operand data type NULL is invalid for sum operator.
But when you execute the following

declare @i int
set @i=null 
select sum(@i)
You get the output as NULL. Eventhough SUM is applied over NULL value, the first one throwed error and second one ran successfully. It is becuase in first case NULL did not have any datatype so SUM couldn't assume whether the NULL is of Number datatypes (INT,FLOAT, DECIMAL,etc). But in the second example @i has NULL value but it is of INT datatype so SUM function worked correctly and returned the value NULL

You can also use implicit convertion

SELECT SUM(NULL+0)
will return NULL becuase adding 0 to it makes it to have datatype of INT. If you try to run this code
SELECT SUM(NULL+GETDATE())
it will throw an error
Msg 8117, Level 16, State 1, Line 1
Operand data type datetime is invalid for sum operator
It is because NULL value is of datatype DATETIME which can not be used on aggregate column
Also default datatype of NULL is INT. Refer Default datatype of NULL for more information

Tags: 


Madhivanan
3 · 39% · 12430
17 Readers Liked this
Olga Medvedeva Liked this on 8/2/2012 1:30:00 AM
Profile · Blog · Twitter
Hardik Doshi Liked this on 8/2/2012 1:42:00 AM
Profile · Facebook
Manas Ranjan Dash Liked this on 8/2/2012 1:46:00 AM
Profile · Blog · Facebook · Twitter
Adam Tokarski Liked this on 8/2/2012 2:04:00 AM
Profile
Jacob Sebastian Liked this on 8/2/2012 6:57:00 AM
Profile · Blog · Facebook · Twitter
Ramesh Velayudhan Liked this on 8/2/2012 8:03:00 AM
Profile
Krishnrajsinh Rana Liked this on 8/3/2012 1:43:00 PM
Profile
plus.google.com/u/0/109572643945069626815 Liked this on 8/4/2012 9:28:00 AM
Profile
Madhivanan Liked this on 8/5/2012 1:18:00 AM
Profile · Blog · Facebook · Twitter
a.diniz Liked this on 8/6/2012 2:19:00 AM
Profile
DBMSAid Liked this on 9/1/2012 3:43:00 PM
Profile
Dave Vroman Liked this on 8/2/2012 9:25:00 AM
Profile
Dattatrey Sindol (Datta) Liked this on 8/2/2012 2:01:00 PM
Profile · Blog
kingkong0924 Liked this on 8/2/2012 9:01:00 PM
Profile
Sandeep Prajapati Liked this on 8/2/2012 10:09:00 PM
Profile · Blog · Facebook · Twitter
Guru Samy Liked this on 8/3/2012 1:25:00 AM
Profile · Blog
Nakul Vachhrajani Liked this on 8/3/2012 6:43:00 AM
Profile · Blog · Facebook · Twitter
17
Liked
 
0
Lifesaver
 
 
 
0
Incorrect



Submit

7  Comments  

  • Madhivanan, the first part of the post says that SUM(NULL) results in error since NULL does not have any data type in this case. But the last statement in the post says that, Default Data Type of NULL is INT. Isn't that conflicting? Thoughts?

    commented on Aug 2 2012 2:03PM
    Dattatrey Sindol (Datta)
    43 · 4% · 1333
  • Datta, thanks for asking that question. When you use NULL it does not have any datatype. But when you use SELECT NULL as col INTO #t, SQL Server should assign a datatype to NULL so that the col will have proper datatype. So by default it assigns INT datatype. This is applicable only when you do SELECT INTO TABLE. Refer that link for more information

    commented on Aug 3 2012 12:31AM
    Madhivanan
    3 · 39% · 12430
  • Thanks Madhivanan for clarifying and for this interesting article as always :)

    commented on Aug 3 2012 1:08AM
    Dattatrey Sindol (Datta)
    43 · 4% · 1333
  • A very interesting post - thank-you, Madhivanan!

    commented on Aug 3 2012 6:44AM
    Nakul Vachhrajani
    4 · 33% · 10575
  • Nakul, thanks for your feedback

    commented on Aug 5 2012 1:18AM
    Madhivanan
    3 · 39% · 12430
  • Good post Madhivanan.

    May I know at which situation this null handling would be help ful?

    Vijay Anand Madhuranayagam http://sqlvijay.wordpress.com/

    commented on Aug 7 2012 5:17AM
    Vijay Anand Madhuranayagam
    2893 · 0% · 2
  • One case is when you use count function to count rows. Some use COUNT(*), COUNT(col), COUNT(1), etc. A user was using COUNT(NULL) which caused the error.

    commented on Aug 7 2012 5:39AM
    Madhivanan
    3 · 39% · 12430

Your Comment


Sign Up or Login to post a comment.

"Typed NULL and non-typed NULL" rated 5 out of 5 by 17 readers
Typed NULL and non-typed NULL , 5.0 out of 5 based on 17 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]