create function expression ( @list varchar(8000), @exp1 varchar(8000), @exp2 varchar(8000)) returns varchar(8000) as begin declare @tmp varchar(8000),@tmp1 varchar(8000) select @list =@list+'!',@tmp='',@tmp1='' declare @i int,@isyh int select @i = 1,@isyh=0while @i < len(@list) begin if substring(@list,@i,1)='"' begin if @isyh = 0 select @isyh = 1 else select @isyh = 0 end else begin if @isyh = 0 select @tmp = @tmp+substring(@list,@i,1) else select @tmp='' end
if @isyh = 0 begin select @tmp1 = @tmp1+substring(@list,@i,1) if right(@tmp,len(@exp1)) = @exp1 begin select @tmp1 = substring(@tmp1,1,len(@tmp1)-len(@exp1))+@exp2 select @tmp = '' end end
else select @tmp1 = @tmp1+substring(@list,@i,1) select @i=@i+1 end return @tmp1 end 自己解决,如上:select dbo.expression('出生日期+出勤="出勤"+出勤','出勤','A12')
(
@list varchar(8000),
@exp1 varchar(8000),
@exp2 varchar(8000))
returns varchar(8000)
as
begin
declare @tmp varchar(8000),@tmp1 varchar(8000)
select @list =@list+'!',@tmp='',@tmp1=''
declare @i int,@isyh int
select @i = 1,@isyh=0while @i < len(@list)
begin
if substring(@list,@i,1)='"'
begin
if @isyh = 0 select @isyh = 1
else select @isyh = 0
end
else
begin
if @isyh = 0 select @tmp = @tmp+substring(@list,@i,1)
else select @tmp=''
end
if @isyh = 0
begin
select @tmp1 = @tmp1+substring(@list,@i,1) if right(@tmp,len(@exp1)) = @exp1
begin
select @tmp1 = substring(@tmp1,1,len(@tmp1)-len(@exp1))+@exp2
select @tmp = ''
end
end
else select @tmp1 = @tmp1+substring(@list,@i,1) select @i=@i+1
end
return @tmp1
end 自己解决,如上:select dbo.expression('出生日期+出勤="出勤"+出勤','出勤','A12')