troubleshooting Question

Need to pull individual address lines 1, 2, 3 from single text field -- similar to VFP MLine

Avatar of PetEdge
PetEdgeFlag for Afghanistan asked on
DatabasesMicrosoft SQL ServerSQL
3 Comments1 Solution243 ViewsLast Modified:
Assume table:  customer
custnum (int), address (text)

Address contains multi-line addresses, ex:
65 Flufferwasser Lane
Mailstop 1234
Charlotte, NC  28202

I need to extract each line, in the format of addressLine1, addressLine2, addressLine3, to an output file.
Ex:  select custnum, (line1 of address) as AddressLine1,  select (line2 of address) as AddressLine2 from customer

In VFP it's easy -- you just use:  select custnum, mline(address,1) as Addressline1,  mline(address,2) as Addressline2 from customer

Any suggestions greatly appreciated.  I've been struggling with nesting charindexes but feel there has to be a better way.  (And yes, I'm stuck with the data in its current format!).
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros