--事务开始
BEGIN TRANSACTION
BEGIN TRY
-----------------------插入主表记录------------------------
INSERT INTO B_BGuide_TB(
[Var_BGuidID],[NVar_Title],[Int_CaseCID],[NVar_Publisher],[Date_PubT],[NVar_FullText],[Var_EntryP],[Nvar_FullContent],Var_ModP,Int_RIDF
)VALUES(
@Var_BGuidID,@NVar_Title,@Int_CaseCID,@NVar_Publisher,@Date_PubT,@NVar_FullText,@Var_EntryP,@Nvar_FullContent,@Var_EntryP,@Int_RIDF
)
-----------------------------------------------------------
--------------------附件表插入数据准备---------------------
--拆分字符串生成临时表
if len(@Var_AAddr) > 0 and len(@NVar_AName) > 0
begin
SELECT identity(int,1,1) AS ID, col AS Var_AAddr INTO #Var_AAddrStrTB
FROM [StrSplit](@Var_AAddr,',')
SELECT identity(int,1,1) AS ID, col AS Float_ASize INTO #Float_ASizeStrTB
FROM [StrSplit](@Float_ASize,',')
SELECT identity(int,1,1) AS ID, col AS Nvar_AName INTO #Nvar_ANameStrTB
FROM [StrSplit](@Nvar_AName,',')
--组装临时表并将数据插入附件表
INSERT INTO B_BGAnnex_TB (Var_BGuidID,Var_AAddr,Float_ASize,Nvar_AName)
SELECT @Var_BGuidID,Var_AAddr,Float_ASize,Nvar_AName
FROM #Var_AAddrStrTB,#Float_ASizeStrTB,#Nvar_ANameStrTB
WHERE #Var_AAddrStrTB.ID=#Float_ASizeStrTB.ID
AND #Var_AAddrStrTB.ID=#Nvar_ANameStrTB.ID
end
-----------------------------------------------------------
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH