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 |
ashley.sql
Constraint Violating Yak Guru
299 Posts |
Posted - 2009-01-11 : 14:49:40
|
I have sql server 2000 and i have data like show below in the tableCREATE TABLE #temp(orderid int, orderyear varchar(50))INSERT #temp SELECT 1,'2009 rejected;2010 rejected' UNION ALLSELECT 2,'2009 rejected;2010' UNION ALLSELECT 3,'2009' UNION ALLSELECT 4,'2010' UNION ALLSELECT 5,'2007 rejected;2008 rejected;2009' Now I want the results to be like:OrderID ORDERYEAR1 20091 20102 20092 20103 20094 20105 20075 20085 2009I need only the numerical part. how do i do this in sql server 2000-----------------------------------------------------------------------------------------------Ashley Rhodes |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-11 : 15:09:56
|
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76733 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-11 : 22:50:54
|
declare @table table(orderid int,orderyear varchar(600) )insert into @tableSELECT 1,'2009 rejected;2010 rejected' UNION ALLSELECT 2,'2009 rejected;2010' UNION ALLSELECT 3,'2009' UNION ALLSELECT 4,'2010' UNION ALLSELECT 5,'2007 rejected;2008 rejected;2009' SELECT s.orderid,LEFT(SUBSTRING(s.orderyear, v.Number - 1,COALESCE(NULLIF(CHARINDEX(';', s.orderyear, v.Number), 0), LEN(s.orderyear) + 1) - v.Number + 1),4) AS valueFROM @table AS sINNER JOIN master..spt_values AS v ON v.Type = 'p'WHERE SUBSTRING(';_' + s.orderyear, v.Number, 1) = ';'Jai Krishna |
|
|
|
|
|
|
|