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.
| Author |
Topic |
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-08-20 : 18:20:08
|
| Hi GuysI have a table named Orders, which has a field called OrderRef. Sample data looks like:O112298/01O112299/01O112299/02O112299/030112300/010112301/010112301/02Everthing before the '/' is the order number, and everything after is the order line. IS there a way to show these two items seperatley, for example:OrderNumber,OrderLineO112298,01O112299,01O112299,02O112299,030112300,010112301,010112301,02Thanking you in advance!!! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-20 : 18:43:01
|
| SELECT LEFT(Column1, 7) AS OrderNumber, RIGHT(Column1, 2) AS OrderLineIf the sizes change, you can use CHARINDEX to locate "/" and then use LEFT/SUBSTRING.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
rcr69er
Constraint Violating Yak Guru
327 Posts |
Posted - 2008-08-21 : 02:55:12
|
| HiThanks for that!How would you use the CHARINDEX as I have a feeling the lengths will change soon.Thanks |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-21 : 03:33:28
|
| select substring(col,1,charindex('/',col)-1),substring(col,charindex('/',col)+1,len(col)) from tableRead about that function in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-21 : 04:17:57
|
| or use parsenameSELECT PARSENAME(REPLACE(OrderRef,'/','.'),2) AS OrderNumber,PARSENAME(REPLACE(OrderRef,'/','.'),1) AS OrderLine FROM Orders |
 |
|
|
|
|
|
|
|