sqlserver去除括号

SELECT
    workcode AS workCode,
    CASE 
        WHEN CHARINDEX('(', lastname) > 0 THEN 
            REPLACE(lastname, SUBSTRING(lastname, CHARINDEX('(', lastname), CHARINDEX(')', lastname) - CHARINDEX('(', lastname) + 1), '')
        WHEN CHARINDEX('(', lastname) > 0 THEN 
            REPLACE(lastname, SUBSTRING(lastname, CHARINDEX('(', lastname), CHARINDEX(')', lastname) - CHARINDEX('(', lastname) + 1), '')
        ELSE
            lastname
    END AS lastName,
    hd.departmentname AS departmentName,
    hjt.jobtitlename AS jobTitleName,
    messagerurl AS imageUrl
FROM HrmResource hr
INNER JOIN HrmDepartment hd ON hd.id = hr.departmentid
INNER JOIN HrmJobTitles hjt ON hjt.id = hr.jobtitle
WHERE status IN (0, 1)

上面代码以泛微OA的SQL server类型数据库为例,可以去除名字中的中英文括号。

你可能感兴趣的:(sqlserver,数据库)