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 IamaSherpa 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 1

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
 
Try something like the following:
Code:
SELECT 
SUBSTR('\NAME\ADDRESS\CITY\STATE', INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 2)+1,
        INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 3)- INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 2)-1) ADDRESS, 
SUBSTR('\NAME\ADDRESS\CITY\STATE', INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 3)+1,
        INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 4)- INSTR('\NAME\ADDRESS\CITY\STATE','\', 1, 3)-1)  CITY
FROM dual;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top