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 2005 Forums
 Transact-SQL (2005)
 remove '- '

Author  Topic 

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-09-11 : 04:23:37
[code]DECLARE @tempfun TABLE ( col1 varchar(10))
INSERT INTO @tempfun SELECT
'- aaaaa' UNION ALL SELECT
'- bbbbb' UNION ALL SELECT
'- ccccc' UNION ALL SELECT
'- ddddd' UNION ALL SELECT
'- eeeee'

SELECT REPLACE(col1, '- ', '')
FROM @tempfun[/code]
can i assume that this way is the fastest and the easiest?
note front 2 character is 100% '- '


Hope can help...but advise to wait pros with confirmation...

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-09-11 : 04:30:41
Never assume anything. Try it out with some other ways of doing it such as substring() or right() or left() and see which is faster for differing amounts of data.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-11 : 04:45:26
using replace() means if you have '- ' anywhere within the string will also be removed.

If you intention is just to remove the 1st 2 character, use SUBSTRING(), RIGHT() or even STUFF(). The performance difference between these function should be very marginal


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -