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

Split-up parts of fields 1

Status
Not open for further replies.

antiskeptic

Programmer
Jul 14, 2004
71
US
I know the title of this post leaves a lot to be desired, But I'm not quite awake yet and the terminology is just not coming to me this morning. *ha*

I am working in SQL Server 2000, and I have a query pulling the basic fields needed for my report. I have one field however, that a little manuvering is required.
It is a unit number and the "format" is:

N000-1234
Vh6-0123
Bldg6-01234

As you can see there really is no format to this number except the dash. Which is all I need to get the piece I need from this field. I need to capture the four or five digit number following the dash in this field. It should be pretty simple, I just have forgotten the syntax. (In an Excel formula, I think it is a FIND command, or something? )
Thank you in advance for any help you can provide. :)

Sincerely,
Antiskeptic
 
Try this:

[tt]SELECT Right([col_name], CharIndex('-', [col_name]) - 1)[/tt]

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
And when you try that it won't work ;)

Try this:

[tt]SELECT Substring([col_name], CharIndex('-', [col_name]) + 1, Len([col_name]))[/tt]

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
cLFlaVA,
Thank you ...I knew it was a simple one. *ha*
THat did the trick. And even in the few feilds that don't have the dash, it simply gives all that is in the feild. It works like a charm. Thank you!!

Sincerely,
Antiskeptic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top