divide fields?

A

Alejandra Parra

How can I divide a field that looks like this
Column
data1/data2
data3/data4
d5/d6

So I can have after the query
Column1 Column2
data1 data2
data3 data4
d5 d6
 
J

John Spencer (MVP)

Permanently or temporarily? Temporary solution

SELECT OriginalColumn,
Left(OriginalColumn,Instr(1,OriginalColumn,"/")-1) as Col1,
Mid(OriginalColumn,Instr(1,OriginalColumn,"/")+1) as Col2
FROM YourTable

Permanent
UPDate YourTable
Set Col1 = Left(OriginalColumn,Instr(1,OriginalColumn,"/")-1)
Col2 = Mid(OriginalColumn,Instr(1,OriginalColumn,"/")+1) as Col2
FROM YourTable
WHERE OriginalColumn like "*/*"
 
D

Dale Fye

Alejandra,

If you are guaranteed to have a "/" in the column, then it is relatively
easy

SELECT LEFT([yourColumn], INSTR([yourColumn], "/") -1) as Column1,
MID([yourColumn], INSTR([yourColumn], "/") +1) as Column2
FROM yourTable

It becomes a bit more difficult if you are not guaranteed to have the "/"

HTH
Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top