查询 去除 数字字母
SELECT a.emp_id as 工号, b.User_Name as 姓名 ,d.Dept_Name as 部门,d.Dept_ID as 部门号, e.name as 职称 ,c.Ide_card as 卡号 ,a.OnBoard_Date as 入职日,a.Off_Date as 离职日 ,b.sn as 个人SN ,b.Photo_Type as 照片类型
from New_User_Info.dbo .Cuser_Info a
left join New_User_Info.dbo.cuser b on b.sn=a.CUser_SN
left join New_User_Info .dbo.Ide_Card_Rec c on c.CUser_SN =b.SN
left join New_User_Info .dbo.CDept d on d.SN =a.CDept_SN
left join New_User_Info .dbo .ctitle_new e on e.SN =a.Job_Title
where c.Ide_card = '15645644'
得到:
部门号 职称
311111 4B工程师
E表里面的职称有2部分,前面数字字母 如何去掉(上面例子是去掉 4B)
条件获取的卡号是随机的, 职称也是随机的,目前可知的事 前面是1-3个不等的数字字母+N个汉字组成
我只想要汉字,有什么好方法?
------解决方案--------------------SELECT a.emp_id as 工号, b.User_Name as 姓名 ,d.Dept_Name as 部门,d.Dept_ID as 部门号,
substring(e.name,PATINDEX('%[吖-做]%', e.name),LEN(e.name)-PATINDEX('%[吖-做]%', e.name)+1) as 职称 ,
c.Ide_card as 卡号 ,a.OnBoard_Date as 入职日,a.Off_Date as 离职日 ,b.sn as 个人SN ,b.Photo_Type as 照片类型
from New_User_Info.dbo .Cuser_Info a
left join New_User_Info.dbo.cuser b on b.sn=a.CUser_SN
left join New_User_Info .dbo.Ide_Card_Rec c on c.CUser_SN =b.SN
left join New_User_Info .dbo.CDept d on d.SN =a.CDept_SN
left join New_User_Info .dbo .ctitle_new e on e.SN =a.Job_Title
where c.Ide_card = '15645644'
------解决方案--------------------declare @S varchar(20)
set @S='4B工程师'
--如果你的汉字都在右边
select right(@S,(DATALENGTH(@S)-len(@S)))
/*
工程师
*/
------解决方案----------------------提取中文
IF OBJECT_ID('DBO.CHINA_STR') IS NOT NULL
DROP FUNCTION DBO.CHINA_STR
GO
CREATE FUNCTION DBO.CHINA_STR(@S NVARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
WHILE PATINDEX('%[^吖-座]%',@S) > 0
SET @S = STUFF(@S,PATINDEX('%[^吖-座]%',@S),1,N'')
RETURN @S
END
GO
PRINT DBO.CHINA_STR('呵呵ABC123ABC')
GO