April 11, 2012 at 3:08 pm
How would you trim a string that looks like this? I need only the string between the first set of backslashes.
\Beverages\Soda Pop\Mountain Dew
-
April 11, 2012 at 3:09 pm
xenophilia (4/11/2012)
How would you trim a string that looks like this? I need only the string between the first set of backslashes.\Beverages\Soda Pop\Mountain Dew
Is the first backslash always in position 1 of the string?
April 11, 2012 at 3:13 pm
yes (thanks again Lynn)
-
April 11, 2012 at 3:15 pm
See if this helps you:
DECLARE @tststr VARCHAR(64);
SET @tststr = '\Beverages\Soda Pop\Mountain Dew ';
SELECT SUBSTRING(RIGHT(@tststr,DATALENGTH(@tststr) - 1),1,PATINDEX('%\%',RIGHT(@tststr,DATALENGTH(@tststr) - 1)) - 1);
April 11, 2012 at 3:24 pm
can i substitute the column name for the @parameter?
eg.
,SUBSTRING(RIGHT('DTS.SuitePath',DATALENGTH('DTS.SuitePath') - 1),1,PATINDEX('%\%',RIGHT('DTS.SuitePath',DATALENGTH('DTS.SuitePath') - 1)) - 1)
as 'SuitePath'
-
April 11, 2012 at 3:25 pm
BTW, the string between the first pair of backslashes will vary in length from row to row
-
April 11, 2012 at 3:26 pm
Yes, but not in quotes.
'DTS.SuitePath' means the literal string value DTS.SuitePath. If it's a column name, it must not be in quotes.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 11, 2012 at 3:27 pm
Instead of constantly asking questions how about trying things out yourself?
April 11, 2012 at 3:28 pm
Hello Gail!
So, that results in empty cells. I know I should post some ddl, but any ideas?
-
April 11, 2012 at 3:29 pm
xenophilia (4/11/2012)
BTW, the string between the first pair of backslashes will vary in length from row to row
And your point? The only fixed point the first \ in the string. I'm not looking for that per your specifications.
April 11, 2012 at 3:30 pm
Are we talking T-SQL code or SSIS?
April 11, 2012 at 3:30 pm
xenophilia (4/11/2012)
Hello Gail!So, that results in empty cells. I know I should post some ddl, but any ideas?
so why dont you post what you know we will ask for? it will get you better answers to your questions.
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
April 11, 2012 at 3:35 pm
ok, because I'm stressed 🙂 I will.
-
April 11, 2012 at 3:46 pm
Here's the query. I am using the column name in place of the parameter. It is a working query before I add the trimming functions (line 2). I know Lynn's select string works great, but when I adopt using column name it fails in my query.
------i get this error
Msg 536, Level 16, State 1, Line 1
Invalid length parameter passed to the substring function.
---query
removed
-
April 11, 2012 at 3:51 pm
Table definitions and sample data please (sample data as insert statements)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 15 posts - 1 through 15 (of 32 total)
You must be logged in to reply to this topic. Login to reply