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


STUFF Function


STUFF Function

Author
Message
Tom Thomson
Tom Thomson
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26130 Visits: 12500
Toreador (5/17/2011)
Koen Verbeeck (5/16/2011)
And the explanation doesn't mention why inserting NULL in another string doesn't result in NULL, but in an empty space instead.


That's what got me.
Surely it's a bug?
select 'Vinay, ' + NULL + ', Amit'
returns NULL, so I'd have thought
select STUFF('Vinay, Vijay, Amit',8,5,NULL)
should do the same?

That's exactly my reaction. The BoL page quoted states that the last expression is inserted in the other, and I'm pretty sure that sticking a NULL in the middle of a string should produce NULL. If it doesn't, I would regard it as a bug unless there were a clear statement in BoL that this operation on NULL was unlike any other in SQL (if there is such a statement, I haven't found it). I wonder if it's affected by the CONCAT_NULL_YIELDS_NULL setting?

Tom

Danny Ocean
Danny Ocean
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2232 Visits: 1549
Toreador (5/17/2011)
Koen Verbeeck (5/16/2011)
And the explanation doesn't mention why inserting NULL in another string doesn't result in NULL, but in an empty space instead.


That's what got me.
Surely it's a bug?
select 'Vinay, ' + NULL + ', Amit'
returns NULL, so I'd have thought
select STUFF('Vinay, Vijay, Amit',8,5,NULL)
should do the same?



Hi,

Few days ago, when i was playing with some strings, i found this . That time i also shocked. I feel that we all should know this. that's why i sumbit this question. i think it help us.


Thx
Vinay

Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com
Kiara
Kiara
SSC Eights!
SSC Eights! (827 reputation)SSC Eights! (827 reputation)SSC Eights! (827 reputation)SSC Eights! (827 reputation)SSC Eights! (827 reputation)SSC Eights! (827 reputation)SSC Eights! (827 reputation)SSC Eights! (827 reputation)

Group: General Forum Members
Points: 827 Visits: 1426
Wow... that didn't work quite the way I'd expected it to! Nice question!

(And I'm really glad I checked my answer in SQL before actually answering the question!)

-Ki
Tom Thomson
Tom Thomson
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26130 Visits: 12500
Danny Ocean (5/17/2011)
Hi,

Few days ago, when i was playing with some strings, i found this . That time i also shocked. I feel that we all should know this. that's why i sumbit this question. i think it help us.


Thx
Vinay

That's a very good reason for posting the question. Thanks, Vinay.

Tom

Thomas Abraham
Thomas Abraham
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3847 Visits: 2256
Another ticky tack problem. Sure, I said 2, because the results were the same, just in a different order. It was the last of the two matching result sets. (No order by clause, so order doesn't matter. :-) )

By the way, what setting in SQL Server Management Studio must I have set that required me to put semicolons at the end of each command before they would run without error?

Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
Mike Is Here
Mike Is Here
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1810 Visits: 513
Nice question!
Jaroslav Pfauser
Jaroslav Pfauser
Right there with Babe
Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)

Group: General Forum Members
Points: 716 Visits: 100
Damn it.
I answered correctly, but there was 2 same answers and I choose the wrong one

Or is there some difference between those 2 answers?

1. Vinay, Anup, Amit 2. Vinay, , Amit 3. NULL
1. Vinay, Anup, Amit 3. NULL 2. Vinay, , Amit

Angry
Tom Thomson
Tom Thomson
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26130 Visits: 12500
I've submitted a connect item suggesting this behavious be changed.

Tom

M&M
M&M
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6111 Visits: 3913
Tom.Thomson (5/17/2011)
I've submitted a connect item suggesting this behavious be changed.


Thank you Tom

M&M
sharath.chalamgari
sharath.chalamgari
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2002 Visits: 798
Good Question and nice to know about the bug in this function.
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