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.
| 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=sblfi would like to get just what is in red. I put this together first select message,SUBSTRING(Message,93,120) as extractinto #sblfextractfrom messagequeue where msgtype like '%export%' and fundcode ='sblf'order by MessageId descwhich returns 6-22\sblf_NOSTROPAYMENT_20120622_7004345_PAYMENT.XLS;@pKeyID=7004345;@ExtractType=PAYMENT;@pFundCode=sblfhow 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. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2012-07-09 : 11:24:00
|
| This will give you the blue if the string changesDECLARE @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)JimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|
|
|