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 开发者_C百科 DCB1000
DCB-100-2 DCB-100
DCB-300-2 DCB-300
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...
Check this out: http://msdn.microsoft.com/en-us/library/aa259342(v=sql.80).aspx
Regards,
Nagendra U M
精彩评论