Author |
Topic |
Sonu619
Posting Yak Master
202 Posts |
Posted - 2011-03-15 : 20:57:42
|
Here is my source dataDescriptionD-1,D2D-2,D-U,T1U-5,T2,K-5,T3NULLHere is the expressions i am using in "Derived Column"Col1 = SUBSTRING(Description,1,FINDSTRING(Description,",",1) - 1)Col2 = SUBSTRING(Description,FINDSTRING(Description,",",1) + 1,FINDSTRING(Description,",",2) - FINDSTRING(Description,",",1) - 1)Col3 = SUBSTRING(Description,FINDSTRING(Description,",",2) + 1,LEN(Description))Col4 = Need help for expressionNote:- I am receiving error "Disposition" Error. Please help me out where i am wrong. Thanks in advance |
|
pduffin
Yak Posting Veteran
68 Posts |
Posted - 2011-03-24 : 19:39:48
|
create the below function in you databasecreate FUNCTION retrive (@in char(50),@Outpos int)RETURNS char(50)ASbegindeclare @out char(50)declare @pos intset @pos = 0declare @indx intset @indx = 1set @in = rtrim(@in) + ', ,' while @indx < len(@in) and @pos < @outpos begin select @out = substring(@in,@indx,charindex(',',@in,@indx) - @indx) select @indx = charindex(',',@in,@indx) + 1,@pos = @pos + 1 endreturn @outend-----------------------------------------then simply:select dbo.retrive(description,1) as col1,dbo.retrive(description,2) as col2dbo.retrive(description,3) as col3dbo.retrive(description,4) as col4from ... |
|
|
pduffin
Yak Posting Veteran
68 Posts |
Posted - 2011-03-24 : 19:40:46
|
not what you asked for but much easier to read and write! |
|
|
|
|
|