Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Char with null


Char with null

Author
Message
tejinder.barnala
tejinder.barnala
SSC Veteran
SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)SSC Veteran (222 reputation)

Group: General Forum Members
Points: 222 Visits: 4
Comments posted to this topic are about the item Char with null
Russell Shilling
Russell Shilling
SSC Eights!
SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)SSC Eights! (924 reputation)

Group: General Forum Members
Points: 924 Visits: 208
The answer is clearly wrong. Some of these questions are really questionable.

The
isnull(left(@b,3),'I ô Char') as ba
will also return the string. The left function of @b returns NULL.

So long, and thanks for all the fish,

Russell Shilling, MCDBA, MCSA 2K3, MCSE 2K3
Rune Bivrin
Rune Bivrin
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3730 Visits: 1466
Russell Shilling (1/10/2017)
The answer is clearly wrong. Some of these questions are really questionable.

The
isnull(left(@b,3),'I ô Char') as ba
will also return the string. The left function of @b returns NULL.

Well, if you'd run the code you'd find it's completely correct.
What's missing in the explanation is the behaviour of ISNULL(). It always derives its return type from the first argument, which in the "ba" case will be char(3) as that is what LEFT() will return.


Just because you're right doesn't mean everybody else is wrong.
sendijunk
sendijunk
SSC Veteran
SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)

Group: General Forum Members
Points: 254 Visits: 81
Good question. Could use a bit more explanation though. Interesting what happens if you replace ISNULL with COALESCE.
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3627 Visits: 3236
sendijunk (1/11/2017)
Good question. Could use a bit more explanation though. Interesting what happens if you replace ISNULL with COALESCE.

The return type depends on "precedence" of types. In this case, the longest string of 8 chars.
Ed Wagner
Ed Wagner
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10328 Visits: 9600
And here I was looking for the trick. ;-) Thanks.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Bob Razumich
Bob Razumich
Mr or Mrs. 500
Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)

Group: General Forum Members
Points: 516 Visits: 1153
Rune Bivrin (1/10/2017)
Russell Shilling (1/10/2017)
The answer is clearly wrong. Some of these questions are really questionable.

The
isnull(left(@b,3),'I ô Char') as ba
will also return the string. The left function of @b returns NULL.

Well, if you'd run the code you'd find it's completely correct.
What's missing in the explanation is the behaviour of ISNULL(). It always derives its return type from the first argument, which in the "ba" case will be char(3) as that is what LEFT() will return.


And for those inquiring minds that would like a quick link for the ISNULL function, https://msdn.microsoft.com/en-us/library/ms184325.aspx.
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8708 Visits: 885
I've been caught by these before so had to try it out.
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16636 Visits: 17024
Rune Bivrin (1/10/2017)
Russell Shilling (1/10/2017)
The answer is clearly wrong. Some of these questions are really questionable.

The
isnull(left(@b,3),'I ô Char') as ba
will also return the string. The left function of @b returns NULL.

Well, if you'd run the code you'd find it's completely correct.
What's missing in the explanation is the behaviour of ISNULL(). It always derives its return type from the first argument, which in the "ba" case will be char(3) as that is what LEFT() will return.


+1

The question itself I thought was a great question but the explanation skipped the important part about the return datatype from ISNULL.

I look forward to the next question from Tejinder and hope the explanation is as good as the question next time.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Revenant
Revenant
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5827 Visits: 4718
Iwas Bornready (1/11/2017)
I've been caught by these before so had to try it out.
Me, too.

Thanks, Tejinder!
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