如何使用SQL Server提取以下内容

时间:2011-06-17 16:42:13

标签: sql-server trim

示例:Front Office Manager 0105212000

只需要10521200,所以我删除了第一个和最后一个字符。

之前:

0105212000

之后:

10521200

这是我到目前为止所提出的。

SELECT DISTINCT NAME, right(DESCRIPTION, 9) as 'DESC', DESCRIPTION 
FROM LABORLEVELENTRY
WHERE LABORLEVELDEFID = '201'
  AND INACTIVE = '0'
ORDER BY NAME

3 个答案:

答案 0 :(得分:1)

SELECT DISTINCT NAME,
  SUBSTRING(DESCRIPTION, 2, LEN(DESCRIPTION)-2) as 'DESC',
  DESCRIPTION 
FROM LABORLEVELENTRY
WHERE LABORLEVELDEFID = '201'
  AND INACTIVE = '0'
ORDER BY NAME

答案 1 :(得分:1)

SELECT SUBSTRING ( DESCRIPTION , 2 , LEN(DESCRIPTION)-2 )

从第二个字符开始,选择除最后一个字符之外的所有其他字符

答案 2 :(得分:0)

怎么样:

select left(right('Front Office Manager 0105212000', 9), 8)

所以:

SELECT DISTINCT NAME, 
    left(right(DESCRIPTION, 9), 8) as 'DESC', DESCRIPTION   
FROM LABORLEVELENTRY 
WHERE LABORLEVELDEFID = '201'   
    AND INACTIVE = '0' 
ORDER BY NAME