Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substring length unknown

Status
Not open for further replies.

amylashley

Programmer
Joined
Aug 8, 2005
Messages
2
Location
US
Is there a way using SQL Queries to extract a substring when the length of it is not known? It seems like such a simple thing but all I see is a SUBSTRING function that requires knowledge of the length of the substring in advance.

Thanks
 
The LEN() function will return the length of a string. CHARINDEX and PATINDEX will return the position of a string within another string. Can you combine these functions to produce the results you're looking for? Good luck!

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Ok thanks. I didn't need the LEN function. But the PatINDEX helped:

KeywordBuys.URL,SUBSTRING(KeywordBuys.URL,charIndex('landerName',KeywordBuys.URL)+11,PATINDEX ( '%&misc%' , KeywordBuys.URL )-(charIndex('lander',URL )+11))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top