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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 get string after character \

Author  Topic 

sharona
Yak Posting Veteran

75 Posts

Posted - 2012-07-09 : 11:05:15
i have the following string
OutputFilename=\\WNPCTAVENS01\EnSIS_FS\envU06\DataExport\Summit Data Extracts\PAYMENT\2012-06-22\sblf_NOSTROPAYMENT_20120622_7004345_PAYMENT.XLS;@pKeyID=7004345;@ExtractType=PAYMENT;@pFundCode=sblf

i would like to get just what is in red.

I put this together first
select
message,
SUBSTRING(Message,93,120) as extract
into #sblfextract
from messagequeue where msgtype like '%export%' and fundcode ='sblf'order by MessageId desc
which returns
6-22\sblf_NOSTROPAYMENT_20120622_7004345_PAYMENT.XLS;@pKeyID=7004345;@ExtractType=PAYMENT;@pFundCode=sblf
how do i get the data after a specific character what is in blue above from the temp table


sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-07-09 : 11:16:48
The third parameter is the number of characters you want in the substring. So change to:
SUBSTRING(Message,98,19) as extract
If you are doing this on a well-controlled string, or as a one-time thing, this may be ok. However, if you are planning to use this in production code, and if there is the possibility that the string might change (in length, contents etc.), this would not be a robust or reliable approach.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-07-09 : 11:24:00
This will give you the blue if the string changes
DECLARE @OutputFilename varchar(1000)='\\WNPCTAVENS01\EnSIS_FS\envU06\DataExport\Summit Data Extracts\PAYMENT\2012-06-22\sblf_NOSTROPAYMENT_20120622_7004345_PAYMENT.XLS;@pKeyID=7004345;@ExtractType=PAYMENT;@pFundCode=sblf'


select substring(@outputfilename, PATINDEX('%sblf_NOSTROPAYMENT_%',@Outputfilename),18)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -