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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql parse possible?

Status
Not open for further replies.

futbwal15

IS-IT--Management
Jan 12, 2007
38
US
here is my code so far:

select
f.matteridstring,
f.custom1,
l.itemtext
from contacts c, parties p, fileinfo f, listbox l
where
l.itemtext like 'Lemon Law%' and
c.contactid = p.contactid and
f.fileno = p.fileno and
f.filetype = l.id

when i run the query i get 3 columns....in the last column i get "Lemon Law" followed by the state abbreviation so it may read: Lemon Law (FL)


what i want to know is is it possible to parse this so it only returns the 12th and 13th characters so i only get the state back?


 
You could try:

[tt]Substring(l.itemtext, 12, 2) As StateAbbreviation[/tt]


Hope this helps.

[vampire][bat]
 
DECLARE @STATE varchar(30)

SET @STATE = 'Lemon Law (FL)'

--Assuming state is two chars directly after first (
SELECT SUBSTRING(@STATE,CHARINDEX('(',@STATE)+1,2)

--or just 12th and 13th char
SELECT SUBSTRING(@STATE,12,2)
 
substring worked great, thanks earthwind.....now i have another question....say i have a field that lists car year, car manufacturer, and car model.....is it possible to parse this into 3 different parts considering they will be different lengths at all times?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top