×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Return field data where number begins

Return field data where number begins

Return field data where number begins

(OP)
I need to return data from an address field (address1) starting where a number exists.
Example:

Sunny Hill Gardens 1601 Sunshine Lane - data in field

1601 Sunshine Lane - data that needs to be returned

The numbers are always in different positions in the field.

Thanks for your help.

RE: Return field data where number begins

ANSI SQL is going to come up empty for this

which database system are you actually running?

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

RE: Return field data where number begins

Use some views:
create view v1 (id,pos) as
select id, position('0' in addrcol) from addrtab
union
select id, position('1' in addrcol) from addrtab
...
select id, position('9' in addrcol) from addrtab


and
create view v2 as
select id, min(pos) as pos
from v1
where pos > 0
group by id


And finally:
select substring(addrcol from (select pos from v2 where v2.id = addrtab.id))
from addrtab



My own test:
SQL>select addrcol,
SQL&substring(addrcol from (select pos from v2 where v2.id = addrtab.id))
SQL&from addrtab;
addrcol
 
========================================
Sunny Hill Gardens 1601 Sunshine Lane
1601 Sunshine Lane
===
Somewhere Else 4 Lost Place
4 Lost Place
===
40 Sutton Place
40 Sutton Place
===
Ending number 6
6
===

RE: Return field data where number begins

jarlh, that's awesome, nice job smile

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

RE: Return field data where number begins

Thank you!
blush

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close