开发者

Stripping a string in SQL Server

开发者 https://www.devze.com 2023-04-02 11:17 出处:网络
I need to strip and display strings of column in SQL Server. The strings are like this Actual StringI want to display in select statement

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

精彩评论

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