0

I need to strip and display strings of column in SQL Server. The strings are like this

Actual String      I want to display in select statement
DCB1000-1             DCB1000
DCB-100-2             DCB-100
DCB-300-2             DCB-300

2 Answers 2

1

Try this:

SELECT SUBSTRING(your_field, 1, 7)
FROM your_table

EDITED:
Well, try this:

SELECT SUBSTRING(your_field, 1, 
    LEN(your_field) - CHARINDEX('-', REVERSE(your_field)))

The idea is to find last "-" char (so first one in reversed string) and get substring from the beginning to there...

Sign up to request clarification or add additional context in comments.

Comments

0

Check this out: http://msdn.microsoft.com/en-us/library/aa259342(v=sql.80).aspx

Regards,
Nagendra U M

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.