SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Annoying NULLs


Annoying NULLs

Author
Message
Steve Jones
Steve Jones
SSC Guru
SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)

Group: Administrators
Points: 147760 Visits: 19440
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
My Blog: www.voiceofthedba.com
antony-688446
antony-688446
SSC-Addicted
SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)SSC-Addicted (484 reputation)

Group: General Forum Members
Points: 484 Visits: 371
Excellent QotD. Got it wrong Crying which means I have learnt something :-) .

Another little bit of the fun with Nulls learnt!
SanjayAttray
SanjayAttray
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5737 Visits: 1619
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.
Mahesh Bote
Mahesh Bote
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2684 Visits: 1286


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
David in .AU
David in .AU
Right there with Babe
Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)

Group: General Forum Members
Points: 798 Visits: 561
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
HBhagat
HBhagat
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1105 Visits: 985
I even tested for all the options and all came null, even adding the value to the variable.
Aaron N. Cutshall
Aaron N. Cutshall
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2837 Visits: 1085
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
Mauricio Morales S
Mauricio Morales S
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1038 Visits: 257
All the queries should return NULL.
Also I tested and the result it's the same.
Aaron N. Cutshall
Aaron N. Cutshall
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2837 Visits: 1085
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
nits.shrivastava2006
nits.shrivastava2006
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
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 ?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search