SQL Clone
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 (260 reputation)SSC Veteran (260 reputation)SSC Veteran (260 reputation)SSC Veteran (260 reputation)SSC Veteran (260 reputation)SSC Veteran (260 reputation)SSC Veteran (260 reputation)SSC Veteran (260 reputation)

Group: General Forum Members
Points: 260 Visits: 6
Comments posted to this topic are about the item Char with null
Russell Shilling
Russell Shilling
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1502 Visits: 209
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
SSCarpal Tunnel
SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

Group: General Forum Members
Points: 4276 Visits: 1534
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
Old Hand
Old Hand (308 reputation)Old Hand (308 reputation)Old Hand (308 reputation)Old Hand (308 reputation)Old Hand (308 reputation)Old Hand (308 reputation)Old Hand (308 reputation)Old Hand (308 reputation)

Group: General Forum Members
Points: 308 Visits: 93
Good question. Could use a bit more explanation though. Interesting what happens if you replace ISNULL with COALESCE.
Carlo Romagnano
Carlo Romagnano
SSCertifiable
SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

Group: General Forum Members
Points: 7642 Visits: 3401
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.

I run on tuttopodismo
Ed Wagner
Ed Wagner
SSC Guru
SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)SSC Guru (51K reputation)

Group: General Forum Members
Points: 51273 Visits: 10844
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
SSC Eights!
SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)SSC Eights! (802 reputation)

Group: General Forum Members
Points: 802 Visits: 1216
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
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

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

Group: General Forum Members
Points: 65022 Visits: 17979
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 Modens 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
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12747 Visits: 5010
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