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
 Parse a field entry

Author  Topic 

fedupjohn
Starting Member

6 Posts

Posted - 2012-08-29 : 08:30:30
I'm new to this site but read it often.

Here is what I have

E:\HostingSpaces\Name\NameLess.com\wwwroot\portals\0\In_Bound_Faxes\25

I have fax to email service sending me emails.
The "I" in "In_Bound" is actually the 64th position in the string
The number at the end is the actual name of the file.
To view this file in an HTML module I need 'In_Bound_Faxes\25'.
The number 25 will grow in length as this unfolds.

I know how to parse a static length string but not a dynamic length string.

When I do this:
Select Left (FaxLocation,64) as Fax_Name from dbo.cf_FaxLocation .
This returns me the first 64 characters.

If I do this:
Select Right (FaxLocation,17) as Fax_Name from dbo.cf_FaxLocation
I works, but, once the file name changes length I'll be dropping a leading character.

I could use a little help

John Hornak

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-08-29 : 09:09:35
DECLARE @str varchar(100) = 'E:\HostingSpaces\Name\NameLess.com\wwwroot\portals\0\In_Bound_Faxes\25'
select SUBSTRING(@str,54,100)


Jim

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

fedupjohn
Starting Member

6 Posts

Posted - 2012-08-29 : 09:21:34
Thanks Jim,

This is what I did

Select SUBSTRING(FaxLocation,63,4000) as Fax_Name
from dbo.cf_FaxLocation where ID = @ID

It returned me '\In_Bound_Faxes\25'
Just what I needed


quote:
Originally posted by jimf

DECLARE @str varchar(100) = 'E:\HostingSpaces\Name\NameLess.com\wwwroot\portals\0\In_Bound_Faxes\25'
select SUBSTRING(@str,54,100)


Jim

Everyday I learn something that somebody else already knew



John Hornak
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-29 : 09:43:17
This is another way to do it!

Select SUBSTRING(FaxLocation,63,datalength(FaxLocation)) as Fax_Name 
from dbo.cf_FaxLocation where ID = @ID


--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page
   

- Advertisement -