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
 How to divide a field into more fields?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2008-04-07 : 10:34:18
Hello,

I have a field like below which has blanks 'b';

CODE
000123'b'99999'b'RED RING

WHAT i want to do is like below?

FIELD1
000123

FIELD2
99999

FIELD3
RED RING

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-07 : 10:38:46
[code]Select
Parsename(Replace(col, '''b''', '.'), 3) as Field1,
Parsename(Replace(col, '''b''', '.'), 2) as Field2,
Parsename(Replace(col, '''b''', '.'), 1) as Field3
from table[/code]

Of course, this work only if your data doesn't contain '.' character and there are no more than four fields you want to separate out.
Otherwise, search for fn_split() here.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -