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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 To search for a string in SP?

Author  Topic 

rajaseeth
Starting Member

3 Posts

Posted - 2009-09-19 : 11:18:01
Hi,

I want to search for a string in Stored Procedure. I am new to SQL. What should i do?.



---Boundary-00=_BLD1cvEPKmuNkgPvUNY3 Content-Type: text/plain; charset=utf-8; name=footer.txt Content-Disposition: attachment; filename="footer.txt" Content-Transfer-Encoding: base64 G:\Test\Attach\footer.txt --------------Boundary-00=_BLD1cvEPKmuNkgPvUNY3--



The above is a string i will be getting from a table. I want to get only the value "G:\Test\Attach\footer.txt". How to go about it.. Can i use Substring or patindex.. Plese help me out?

Thanks
Raja

Andreas
Starting Member

11 Posts

Posted - 2009-09-19 : 12:02:05
If you know that the rest of the string always will look exactly the same then you can use this:

declare
@Str varchar(2000),
@StartPos int,
@Length int

set @Str = '---Boundary-00=_BLD1cvEPKmuNkgPvUNY3 Content-Type: text/plain; charset=utf-8; name=footer.txt Content-Disposition: attachment; filename="footer.txt" Content-Transfer-Encoding: base64 G:\Test\Attach\footer.txt --------------Boundary-00=_BLD1cvEPKmuNkgPvUNY3--'
set @StartPos = charindex('Content-Transfer-Encoding: base64', @Str) + len('Content-Transfer-Encoding: base64')
set @Length = charindex('--------------Boundary-00=_BLD1cvEPKmuNkgPvUNY3--', @Str) - @StartPos
select ltrim(rtrim(substring(@Str, @StartPos, @Length)))
Go to Top of Page

rajaseeth
Starting Member

3 Posts

Posted - 2009-09-21 : 10:25:21
Hi,

Actually there will be more than 1 filepath like the below

---Boundary-00=_BLD1cvEPKmuNkgPvUNY3 Content-Type: text/plain; charset=utf-8; name=footer.txt Content-Disposition: attachment; filename="footer.txt" Content-Transfer-Encoding: base64 G:\Test\Attach\footer.txt --------------Boundary-00=_BLD1cvEPKmuNkgPvUNY3-- ------_=_NextPart_002_01C84D7E.9133E008-- ------_=_NextPart_001_01C84D7E.9133E008 Content-Type: application/vnd.ms-excel; name="Press.xls" Content-Description: Press list for partners.xls Content-Disposition: attachment; filename="Press.xls" Content-Transfer-Encoding: base64 g:\test\Attach\Deb\Press.xls ------_=_NextPart_001_01C84D7E.9133E008--


How to get the "G:\Test\Attach\footer.txt"

Thanks,
Raja
Go to Top of Page

Andreas
Starting Member

11 Posts

Posted - 2009-09-21 : 10:45:22
Just apply the same logic, if you know what parts surrounds the string you want then just fetch charindexes for those and read what's in between.
Go to Top of Page
   

- Advertisement -