日期:2014-05-18 浏览次数:20425 次
ALTER PROCEDURE [dbo].[AddEquipmentApplyDetails] ( @EADEaID int = null, @EADVbiCode varchar(50) = null, @EADEbiCode varchar(50) = null, @EADSpecification int = null, @EADUnit int = null, @DADNum int = null, @DADDesc varchar(200) = null, @EADFillTime datetime = null, @EADFillPerson varchar(20) = null, @EADUpdateTime datetime = null, @EADUpdatePerson varchar(20) = null, @EBIName varchar(50) = null ) AS BEGIN set xact_abort on BEGIN TRAN DECLARE @EBICode varchar(50) SET @EBICode =(SELECT EBICode FROM EquipmentBaseInfo WHERE EquipmentBaseInfo.EBIName= @EBIName) INSERT INTO [VHC_WareHouse].[dbo].[EquipmentApplyDetails] VALUES ( @EADEaID , @EADVbiCode, @EBICode, @EADSpecification, @EADUnit, @DADNum, @DADDesc, @EADFillTime, @EADFillPerson, @EADUpdateTime, @EADUpdatePerson) commit tran END
--当取的不是一条记录是会有问题 SET @EBICode =(SELECT top 1 EBICode FROM EquipmentBaseInfo WHERE EquipmentBaseInfo.EBIName= @EBIName) --还有[EquipmentApplyDetails]列建议写全,因为如果后面的值传的和列不等(假设无自增列),则有错 --以后你如果改了表EquipmentApplyDetails,新增了一列,则你的此存储过程必须改,这种设计 --是不合理的,因此建议把列写了
------解决方案--------------------
ALTER PROCEDURE [dbo].[AddEquipmentApplyDetails] ( @EADEaID int = null, @EADVbiCode varchar(50) = null, @EADEbiCode varchar(50) = null, @EADSpecification int = null, @EADUnit int = null, @DADNum int = null, @DADDesc varchar(200) = null, @EADFillTime datetime = null, @EADFillPerson varchar(20) = null, @EADUpdateTime datetime = null, @EADUpdatePerson varchar(20) = null, @EBIName varchar(50) = null ) AS BEGIN set xact_abort on BEGIN TRAN INSERT INTO [VHC_WareHouse].[dbo].[EquipmentApplyDetails] select @EADEaID , @EADVbiCode, EBICode , @EADSpecification, @EADUnit, @DADNum, @DADDesc, @EADFillTime, @EADFillPerson, @EADUpdateTime, @EADUpdatePerson FROM EquipmentBaseInfo WHERE EquipmentBaseInfo.EBIName= @EBIName commit tran END --最好给出测试数据