May 7, 2010 at 1:07 pm
column1
\\abc\tri\eds\rf
\\fd\tri\ef\
\\ghij\tri\gf\rf\k
'
'
'
i got some rows like that in a column
now i want to get the result set like
\\abc\tri\eds
\\fd\tri\ef
\\ghij\tri\gf
simply from first '\' to end of 4th '\'
Thnaq in advance for ur help guys...
i'm really learning lot of different stuff from u guys...
May 7, 2010 at 1:17 pm
Okay, similar yet different from your other post, so what have you tried to solve this problem?
May 7, 2010 at 1:19 pm
neliii (5/7/2010)
column1\\abc\tri\eds\rf
\\fd\tri\ef\\ghij\tri\gf\rf\k
'
'
'
i got some rows like that in a column
now i want to get the result set like
\\abc\tri\eds
\\fd\tri\ef
\\ghij\tri\gf
simply from first '\' to end of 4th '\'
Thnaq in advance for ur help guys...
i'm really learning lot of different stuff from u guys...
To follow suit with your other thread you had:
--Code removed to see what OP has done. Thanks Lynn
-- Cory
May 7, 2010 at 1:23 pm
previously i worked on fixed lenth part of string
so i used to use substring and charindex with a particular length
but here the string lenght between 1st'\' and fourth '\' is varying in all the rows ..i'e 1st row string lenght varies with 2nd row and all
so i couldn't figure t out how to use that functions for that type of rows
May 7, 2010 at 1:24 pm
Care to post what you had? I have a solution, it may not be the best (Back to substring over stuff), but I am curious as to what you have.
-- Cory
May 7, 2010 at 1:29 pm
Do all the values in the column have at least four \'s?
May 7, 2010 at 1:35 pm
Lynn Pettis (5/7/2010)
Do all the values in the column have at least four \'s?
Good question, a follow up question is do you just want to get rid of everything past the last "\"?
String = \\abc\def\ghi\jklmnop
expected result = \\abc\def\ghi
-- Cory
May 7, 2010 at 1:38 pm
@cory
yes exactly cory
May 7, 2010 at 1:42 pm
@cory
thanq for ur response
but what if i had
\\abc\xyz\wzy\123\toi
and i want to get only
\\abc\xyz\wzy
May 7, 2010 at 1:44 pm
This is why we are looking for requirements.
-- Cory
May 7, 2010 at 1:46 pm
Edit: code removed, valuable lesson in progress. Sorry guys, I worked on this for a while and posted without looking for responses.
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
May 7, 2010 at 2:26 pm
i tried to learn how to get that but couldnt...
please help me out with that
May 7, 2010 at 4:52 pm
All we wanted is for you to post the code you have written to try and solve your problem.
Here is my solution using the dbo.DelimitedSplit inline TVF. Use the site search box and type DelimitedSplit.txt to find the thread where I have it uploaded.
create table #TestTab (
Col1 varchar(32)
);
insert into #TestTab
select '\\abc\tri\eds\rf' union all
select '\\fd\tri\ef\' union all
select '\\ghij\tri\gf\rf\k';
select
stuff(
(select '\' + ds.Item from #TestTab t1 cross apply dbo.DelimitedSplit(t1.Col1,'\') ds where ds.ItemID <= 5 and t1.Col1 = t2.Col1 for xml path (''))
,1,1,'')
from
#TestTab t2;
Any one else with a solution, please post it now. Let's see what other options we have for this solution.
Viewing 15 posts - 1 through 15 (of 19 total)
You must be logged in to reply to this topic. Login to reply