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

How to query for sub-string of records?

Status
Not open for further replies.

omoo

Programmer
May 30, 2005
87
US
Hi,

I have the follow records:
N1235-A123-U876
M2345-R434-T365
N1235-A168-U824
M3457-Z541-F234
M4321-R354-U543

I want to have the following distinct output:
N1235-A
M2345-R
M3457-Z
M4321-R
The output is the 1st 5 characrters and "-" and on more character after that. May I know how I can do this?
 
SELECT DISTINCT SUBSTRING(ColumnName FROM 1 FOR 7) AliasName
FROM TableName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I have tried the suggested query but I get a "missing right parenthesis" error. I am using SQL 8.1.
 
I'm sorry. The program I am using is PL/SQL Developer version 5.1
 
Hi,

I have got it. I use SUBSTR(column_name, 1, 7)

Thanks for the help!
 
Next time, to get more accurate answer, ask in the right forum.
I don't think the function you use is ANSI SQL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top