执行插入的存储过程
ALTER PROC [dbo].[proc_Products_InfoUpdate]
@FminAmount VARCHAR(MAX),
@FmaxAmount VARCHAR(MAX),
@FrateFloating VARCHAR(MAX)
AS
INSERT INTO dbo.Rate_Floating(bakProcId,minAmount,maxAmount,rateFloating)
SELECT @id,A.istr,B.istr,C.istr from dbo.fsplit(@FminAmount,‘,‘) AS A
INNER JOIN dbo.fsplit(@FmaxAmount,‘,‘) AS B ON A.id=B.ID
INNER JOIN dbo.fsplit(@FrateFloating,‘,‘) AS C ON A.id=C.ID
上面的 @FminAmount 、@FmaxAmount、@FrateFloating 是参数
如下:@FminAmount 的值为:张三,李四,王五 @FmaxAmount值为:男,女,男 以此类推
张三 |
男 |
19 |
李四 |
女 |
20 |
王五 |
男 |
19 |
dbo.fsplit是一个自定义函数,需要传入的参数是:需要分割的字符串,分割字符
ALTER function [dbo].[fsplit](
@str varchar(8000)
,@spli varchar(10)
)
returns @re table(id int identity,istr varchar(8000))
as
begin
declare @i int,@splen int
select @splen=len(@spli) ,@i=charindex(@spli,@str)
while @i>0
begin
insert into @re values(left(@str,@i-1) )
select @str=substring(@str,@[email protected],8000)
,@i=charindex(@spli,@str)
end
if @str<>‘‘ insert into @re values(@str)
return
end