SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to fiind data inside of a string


how to fiind data inside of a string

Author
Message
ericb1
ericb1
SSC-Enthusiastic
SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)

Group: General Forum Members
Points: 198 Visits: 337
Any help is greatly appreciated. I'm using SQL server 2000 and a have a field that contains a file path like this:

D:\MailRoomImporter\incoming_documents\releases\OC\11000248.pdf

and I'm trying to parse out the directory "releases". The starting position will always be the same, right after: "D:\MailRoomImporter\incoming_documents\" but the directory name and length can change.

So essentially I'm trying to find the field after: "D:\MailRoomImporter\incoming_documents\" and before the next "\"

So far I have:


SELECT FileName,
LTRIM(RTRIM(SUBSTRING(
/* */ FileName,
/* */ CHARINDEX('documents\',FileName,1) +10,
/* */ CHARINDEX('documents\', SUBSTRING(FileName,
CHARINDEX('\', FileName, 1) + 19, 99))

But this is returning some additional characters after releases. Any help is greatly appreciated, thanks!
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12029 Visits: 8918
So is this what you are looking for ?

declare @myfile varchar(256)
set @myfile='D:\MailRoomImporter\incoming_documents\releases\OC\11000248.pdf'
Select datalength(@myfile)
SELECT @myfile
, substring(@myfile, 40, datalength(@myfile)) as TheRest
, CHARINDEX('\',substring(@myfile, 40, datalength(@myfile)),1) as theslash
, substring( substring(@myfile, 40, datalength(@myfile)), 1, CHARINDEX('\',substring(@myfile, 40, datalength(@myfile)),1) - 1 ) as LookingForThis




LookingForThis results in the text 'releases'

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
ericb1
ericb1
SSC-Enthusiastic
SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)

Group: General Forum Members
Points: 198 Visits: 337
awesome! Thank you. But how do I format this so that I can use it as part of a regular query and use a column name as @myfile?

Thanks again!
ericb1
ericb1
SSC-Enthusiastic
SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)

Group: General Forum Members
Points: 198 Visits: 337
I figured it out, thanks again!
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12029 Visits: 8918
Just replace the @var with the column name in the select clause.
I tend to test with @-variables so there is no residue left behind afterwards.

Glad you figured it out Wink

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7773 Visits: 25280
This might be of use to you
CREATE PROCEDURE Dbo.Parse_Charfieldforavalue_02
@HayStack VARCHAR(200),
@Find VARCHAR(50)
AS
DECLARE @Here Int
DECLARE @There Int
DECLARE @TheNeedle VARCHAR(200)

SET @Here = 0
SET @There = LEN(RTRIM(@HayStack))

SET @Here = PATINDEX('%' + @Find + '%',@HayStack)
/* to make even more flexible replace \ in line below with another input variable */
SET @There = PATINDEX('%\%',SUBSTRING(@HayStack,@Here,@There - @Here))

SET @TheNeedle = ''
SET @TheNeedle = SUBSTRING(@HayStack,@Here,@There -1)
SET @There = @Here + @There -1
/* Adjust to take out the whimsy */
SELECT @TheNeedle AS 'Found ',@Here-1 AS 'Between here', @There AS 'And there' -- Found the needle in the hay stack hurrah

/* Useage:
Parse_Charfieldforavalue_02 'D:\MailRoomImporter\incoming_documents\releases\OC\11000248.pdf','releases' */

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search