Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 STUFF Function

Author  Topic 

darinh
Yak Posting Veteran

58 Posts

Posted - 2003-05-05 : 22:13:59
Hi,

This article [url]http://www.sqlteam.com/item.asp?ItemID=11499[/url] has the following line:-

select @array = stuff(@array, 1, @separator_position, '')


Since I had never used the STUFF function I had to consult BOL to figure out how it worked.
What I am wondering is if the STUFF function has any benefits over using

select @array = right(@array, len(@array) - @seperator_position)

which I think would do the same thing. It is hard to easily test using QA since you don't get an execution plan.

Thanks.



Edited by - darinh on 05/05/2003 22:15:54

X002548
Not Just a Number

15586 Posts

Posted - 2003-05-06 : 10:38:33
DAMN...another function I didn't know anything about!

I get identical execution plans::



DECLARE @bk_array varchar(255), @bk_separator_position int

SELECT @bk_array = '1234567890', @bk_separator_position = 2

SELECT @bk_array = stuff(@bk_array, 1, @bk_separator_position, '')

SELECT @bk_array

SELECT @bk_array = '1234567890', @bk_separator_position = 2

SELECT @bk_array = right(@bk_array, len(@bk_array) - @bk_separator_position)

SELECT @bk_array

SELECT @bk_array = stuff(Name, 1, @bk_separator_position, '') FROM Sysobjects Where Name = 'sysobjects'

SELECT @bk_array

SELECT @bk_array = right(Name, len(Name) - @bk_separator_position) FROM Sysobjects Where Name = 'sysobjects'

SELECT @bk_array



Brett

8-)

Edited by - x002548 on 05/06/2003 10:39:11
Go to Top of Page
   

- Advertisement -