开发者

Stripping a string in SQL Server

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜