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!

Substr and INstr

Status
Not open for further replies.

jasonhuibers

Programmer
Sep 12, 2005
290
CA
SELECT
SUBSTR('\NAME\ADDRESS\CITY\STATE' , INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 2)-5 ) ADDRESS,
SUBSTR('\NAME\ADDRESS\CITY\STATE' , INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 2)-5 ) CITY
FROM dual;

How can I change this query to return ADDRESS and CITY in seperate columns as the result?

COL1: ADDRESS
COL2: CITY
 
This looks to be Oracle, rather than SQL Server. But.....

What does this give you?
Code:
SELECT
SUBSTR('\NAME\ADDRESS\CITY\STATE' , INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 2)-5 ) ADDRESS,
SUBSTR('\NAME\ADDRESS\CITY\STATE' , INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 3)-5 ) CITY
FROM dual;

INSTR has a nice parameter "occurance", which is documented here:
 
This gives me:

Address: City:
\NAME\ADDRESS\CITY\STATE DRESS\CITY\STATE
 
This gives me:

Address column: \NAME\ADDRESS\CITY\STATE
City column: DRESS\CITY\STATE
 
I'd suggest posting this in the Oracle forum. While some of the posters on this forum (Microsoft SQL Server: Programming) might know Oracle and be able to help, you'll get your best help from the Oracle thread.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top