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 6, 2009 10:56 AM


SSC-Dedicated

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

Group: Administrators
Last Login: Yesterday @ 8:53 PM
Points: 33,204, Visits: 15,353
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 6, 2009 3:11 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 3:12 PM
Points: 268, Visits: 306
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 7, 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: Thursday, July 17, 2014 10:56 AM
Points: 3,924, Visits: 1,607
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: Friday, August 29, 2014 2:57 AM
Points: 1,093, Visits: 1,222

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: Yesterday @ 6:29 PM
Points: 522, Visits: 555
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, August 26, 2014 4:45 AM
Points: 446, Visits: 659
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


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, August 4, 2014 6:48 AM
Points: 1,111, Visits: 542
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 1, 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 1, 2009 2:47 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, August 4, 2014 6:48 AM
Points: 1,111, Visits: 542
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 6, 2009 11:33 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 7, 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