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


NULLS


NULLS

Author
Message
Robin Sasson
Robin Sasson
SSC Eights!
SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)

Group: General Forum Members
Points: 927 Visits: 530
Comments posted to this topic are about the item NULLS

Exclamation "Be brave. Take risks. Nothing can substitute experience." Exclamation
bitbucket-25253
bitbucket-25253
SSCrazy Eights
SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)

Group: General Forum Members
Points: 9663 Visits: 25280
Nice question to end the week ....

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Koen Verbeeck
Koen Verbeeck
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35237 Visits: 13270
Great question, thanks.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13367 Visits: 12186
Good question, but a BIG mistake in the explanation!!

"COALESCE returns a datatype from the first non-null value in the statement depending on data type precedence"
The datatype of the first non-null value is irrelevant. COALESCE will first consider the data types of ALL arguments, then apply data type precedence rules to them, and then use the result as the data type of the result. Here is a simple repro:

DECLARE @number int, @text varchar(20);
SET @number = NULL;
SET @text = 'three';
SELECT COALESCE(@number, @text);
go
DECLARE @number int, @text varchar(20);
SET @number = NULL;
SET @text = 'three';
SELECT COALESCE(@text, @number);


The integer parameter is null; the first (and only) non-null parameter is varchar. And yet, both the COALESCE statements fail because they try to convert the result to an integer - the highest precedence datatype of the two.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11228 Visits: 7329
Thanks for the qiuestion.
Also, thanks to Hugo for correcting the faulty explanation

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Robin Sasson
Robin Sasson
SSC Eights!
SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)SSC Eights! (927 reputation)

Group: General Forum Members
Points: 927 Visits: 530
Thank you all for the comments and especially to Hugo.

I love SQLServerCentral.com - I learn something new every day and the help and assistance of other members is readily available.

Exclamation "Be brave. Take risks. Nothing can substitute experience." Exclamation
Prasune Verma
Prasune Verma
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 82
I got the answer right but only after removing 'Null' from the declaration of the Local Variable.

When I parse my declaration of the Local Variable, it says "Cannot assign a default value to a local Variable"
So, I removed the Null from my declaration and got my answers correct.

Anyway, nice question. Knowledgeable indeed!!! :-)
Nakul Vachhrajani
Nakul Vachhrajani
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2599 Visits: 2147
Nice, easy question to end the week.

@Hugo: Completely agree on your point about the issue with the explanation.

Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Be courteous. Drive responsibly.

Follow me on
Twitter: @sqltwins
Google Plus: +Nakul
Lucy Dickinson
Lucy Dickinson
SSC Journeyman
SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)

Group: General Forum Members
Points: 89 Visits: 107
Nice question Robin.

Lucy Dickinson
BI SQL Developer
Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13367 Visits: 12186
Prasune Verma (5/11/2012)
I got the answer right but only after removing 'Null' from the declaration of the Local Variable.


So I guess you are running SQL Server 2005 or older?
The ability to assign a value to a variable on the DECLARE statement (as used in the QotD) was added in SQL Server 2008.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
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