日期:2014-05-17 浏览次数:20481 次
begin try
begin tran
insert order ...
insert orderpro
commit tran
end try
begin catch
rollback tran
return
end catch
create proc sp_insertorder
(
@SplitString text, -- 你的字符串
@Separator varchar(2) = '
------解决方案--------------------
'-- 分隔符
)
as
begin try
begin tran
-- DECLARE @SplitString text --
--DECLARE @Separator varchar(2)
DECLARE @CurrentIndex int;
DECLARE @NextIndex int;
DECLARE @ReturnText varchar(8000);-- NVarChar(4000)
SELECT @CurrentIndex=1;
WHILE(@CurrentIndex<=datalength(@SplitString)) -- DATALENGTH(@SplitString)/2
BEGIN
SELECT @NextIndex=charindex(@Separator,@SplitString,@CurrentIndex);
IF(@NextIndex=0 OR @NextIndex IS NULL)
SELECT @NextIndex=datalength(@SplitString)+1;--DATALENGTH(@SplitString)/2
SELECT @ReturnText=substring(@SplitString,@CurrentIndex,@NextIndex-@CurrentIndex);
set @ReturnText = 'select '''+replace(@ReturnText,'-',''',''')+''''
insert dbo.orderpro
(
--......这里的顺序必须与你字符串里给的顺序一致
)
exec (@str)
SELECT @CurrentIndex=@NextIndex+1;
END
commit tran
end try
begin catch
rollback tran
return
end catch