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 2008 Forums
 Transact-SQL (2008)
 Replace function does not work

Author  Topic 

hs123456
Starting Member

6 Posts

Posted - 2010-03-05 : 09:36:46
I have a field with values separated by two spaces like in @string

declare @string varchar(max)
SET @string = 'ABC Company XYZ Company DEF Company'
SELECT CASE
WHEN @string IS NULL THEN 'N/A'
ELSE REPLACE(@string, '<br>',' ')
END AS Company


This does not work. The end result I want is below and it should be part of select statement:

ABC Company
XYZ Company
DEF Company

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-05 : 09:46:25
just make a little change:
replace(@string,'old_value','new_value)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-05 : 10:09:41
You need a SPLIT function. Search for it here

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-05 : 10:29:14
will there be always only maximum of 3 or 4 values to split?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-05 : 10:36:09
quote:
Originally posted by visakh16

will there be always only maximum of 3 or 4 values to split?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




In that case you can use parsename function

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-05 : 11:23:46
quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

will there be always only maximum of 3 or 4 values to split?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




In that case you can use parsename function

Madhivanan

Failing to plan is Planning to fail


exactly
that was my point

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -