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
 General SQL Server Forums
 New to SQL Server Programming
 split string

Author  Topic 

Clas
Starting Member

33 Posts

Posted - 2009-12-02 : 05:07:01
Hi

How to split a string into 4 new fields and get the characters, except -

1234-56-58-987 --> 1234 56 58 987
5478-98-21-6587 --> 5478 98 21 6587
9875-75-11-55 --> 9875 75 11 55




create table #temp
(
ID nvarchar(15),
A int,
B int,
C int,
D int
)

insert into #temp
values
('1234-56-58-987',0,0,0,0),
('5478-98-21-6587',0,0,0,0),
('9875-75-11-55',0,0,0,0)

UPDATE #temp ............



Thanks in advance !

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-02 : 05:14:24
Try like this


select parsename(replace('1234-56-58-987','-','.'),4)
, parsename(replace('1234-56-58-987','-','.'),3)
, parsename(replace('1234-56-58-987','-','.'),2)
, parsename(replace('1234-56-58-987','-','.'),1)

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

Clas
Starting Member

33 Posts

Posted - 2009-12-02 : 05:22:23


THANKS !
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2009-12-02 : 05:51:11
Also note that parsename works only for 4 parts.It wont work for 1234-56-58-987-0000.

PBUH
Go to Top of Page
   

- Advertisement -