Connecting Tech Pros Worldwide Forums | Help | Site Map

Why does MSSQL server allow the attached code to work

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: Oct 1 '09
Why can we define a integer datatype and pass an empty string in that gets evaluated to zero rather than NULL?


declare @testinteger integer
select @testinteger = ''
select @testinteger


How can we get this to eval to NULL?

ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Oct 1 '09

re: Why does MSSQL server allow the attached code to work


Because there's an explicit conversion of data. Read this, on the lower part there's a table that describe the im/explicit conversions.

Try this instead:

Expand|Select|Wrap|Line Numbers
  1.  
  2. declare @testinteger integer
  3. select @testinteger = NULL
  4. select @testinteger 
  5.  
  6.  
Reply


Similar Microsoft SQL Server bytes