Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Annoying NULLs Expand / Collapse
Author
Message
Posted Monday, April 06, 2009 10:56 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 9:24 AM
Points: 31,433, Visits: 13,748
I checked this on 2005, and both answers marked as correct (A and D) work.

You have to run each SET/SELECT and then a SELECT @Val for each answer, with separate executions. I added a drop table #empty at the end as well.

The question has been edited to say "select all that apply"

and I'm awake, Hugo!







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #691263
Posted Monday, April 06, 2009 3:11 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC 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!
Post #691489
Posted Tuesday, April 07, 2009 9:18 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall 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.
Post #692163
Posted Monday, April 13, 2009 11:56 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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
Post #696316
Posted Tuesday, April 14, 2009 12:10 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr 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
Post #696319
Posted Thursday, April 16, 2009 5:19 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-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.
Post #698299
Posted Thursday, April 16, 2009 6:37 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!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
Post #698346
Posted Friday, May 01, 2009 2:43 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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.
Post #708778
Posted Friday, May 01, 2009 2:47 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!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
Post #708780
Posted Wednesday, May 06, 2009 11:33 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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 ?
Post #711767
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse