|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Today @ 9:24 AM
Points: 31,433,
Visits: 13,748
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Tuesday, April 30, 2013 7:26 PM
Points: 254,
Visits: 277
|
|
Excellent QotD. Got it wrong which means I have learnt something .
Another little bit of the fun with Nulls learnt!
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Friday, March 15, 2013 2:43 PM
Points: 3,924,
Visits: 1,554
|
|
I doubt if I can one day master the use of " NULL ". No matter how much I try to understand it, there always something left. Well, " NULL " value handling is most of time are pain in the B**t.
very good QOD.
SQL DBA.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 6:22 AM
Points: 1,074,
Visits: 1,205
|
|
Create Table #Table ( val int ) Go
Select val From #Table Go
Declare @val int Select @val Go
Declare @val int Set @val = Null Select @val Go
Declare @val int Select @val = Null From #Table Select @val Go
Declare @val int Select @val = val From #Table Select @val Go
Declare @val int Select @val = (Select val From #Table) Select @val Go
Drop Table #Table Go
All the options mentioned in QoD returns NULL. So ideally speaking answer should contain all the options.
Mahesh
MH-09-AM-8694
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Sunday, March 17, 2013 5:34 PM
Points: 521,
Visits: 543
|
|
Don't forget to set the initial value of @val to -1 before each pass, you won't get the correct answers if you don't.
-d
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 8:15 AM
Points: 406,
Visits: 597
|
|
| I even tested for all the options and all came null, even adding the value to the variable.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 9:57 AM
Points: 895,
Visits: 504
|
|
harsha.bhagat1 (4/16/2009) I even tested for all the options and all came null, even adding the value to the variable. Check out the code that I posted last week and compare it to yours.
"...when ye are in the service of your fellow beings ye are only in the service of your God." -- Mosiah 2:17
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, February 22, 2011 12:36 PM
Points: 1,022,
Visits: 257
|
|
All the queries should return NULL. Also I tested and the result it's the same.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 9:57 AM
Points: 895,
Visits: 504
|
|
Mauricio Morales Soto (5/1/2009) All the queries should return NULL. Also I tested and the result it's the same. You have to reset the variable to -1 before each test. See the code I posted earlier.
"...when ye are in the service of your fellow beings ye are only in the service of your God." -- Mosiah 2:17
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 07, 2009 6:36 AM
Points: 5,
Visits: 2
|
|
Hi All, I got null value for the below statement
set @val = null but for the below statement
select @val = (select val from #empty) i got
Invalid object name '#empty'
Is it i have to declare #empty first ?
|
|
|
|