USE [hjcs]
GO
/****** Object: UserDefinedFunction [dbo].[GetZjm] Script Date: 2020/4/21 14:05:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER FUNCTION [dbo].[GetZjm] (@text varchar(100))
RETURNS varchar(100) AS
BEGIN
declare @zjm varchar(100), @tmp_char varchar(2),@tmp_zjm varchar(2), @i int,@length int
set @zjm =''
set @length = len(@text)
set @i = 1
while @i<=@length
begin
set @tmp_char = substring(@text,@i,1)
select @tmp_zjm = zjm from hz_zjm where hanzi=@tmp_char
if @@rowcount=1
set @zjm = @zjm +Rtrim(@tmp_zjm)
set @i = @i + 1
end
return (@zjm)
END
使用:
select dbo.GETzjm(shpchd) from spkfk_hj where shpchd='杭州民生健康药业有'