SQL query help – SQL Server

35 pts.
Tags:
SQL Query
SQL Server 2008
SQL statement
Okay, I hope I can explain my dilemma... I need a SQL select statement that will Select part_number from RCTOOL the column part_number has values such as BR643-0034-344-34 AS54-54689 A77360-3454-34456-4 B7374-343-33-32-356-433-11-1 In each of these cases ALL we want it to return is the values UP to the last - Desired result set from example above BR643-0034-344 AS54 A77360-3454-34456 B7374-343-33-32-356-433-11 Thank you in advance
ASKED: July 23, 2013  4:05 AM
UPDATED: July 23, 2013  12:51 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    Your question was the same as what you put into the 'Answer'. It just wasn't well formatted. (I assume that you don't really want your question logged as its own 'Answer'. Anyone scanning for unanswered questions would miss yours.) Since you're asking about MS SQL Server, you can use REVERSE() and RTRIM() to get the characters in reverse order. You can then use CHARINDEX() to find how many characters from the end of the reversed and trimmed value is the first "-" character. 
    CHARINDEX('-',REVERSE(RTRIM( part_number )))
     LEN() will tell you how many characters are in a trimmed value. The difference between that value and the previous value tells you how many characters need to be extracted from the left with LEFT(). So, something like this:
    LEFT( part_number , ( LEN(RTRIM( part_number )) - CHARINDEX('-',REVERSE(RTRIM( part_number )))))
    That should be close, but it's untested. You might have to balance parentheses. It would be easy if the developers had designed the column reasonably. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following