ALTER PROCEDURE [dbo].[addTB_IncomInfo]
(
@CommodityID int,
@WarehousePeople nvarchar(30),
@WarehouseID int,
@ArrivalDate datetime,
@StorageDate datetime,
@CommodityQuanlity float,
@Remark nchar(10)=null,
@unit nvarchar(20),
@returnvalue int=1 output)
AS
declare @s float
set @s=(select [Quantity] from dbo.TB_InventoryInfo where CommodityID=@CommodityID and WarehouseID=@WarehouseID)
if @s=null
begin
insert into dbo.TB_IncomInfo(CommodityID,WarehousePeople,WarehouseID,ArrivalDate,StorageDate,CommodityQuanlity,unit,Remark)
values(@CommodityID,@WarehousePeople,@WarehouseID,@ArrivalDate,@StorageDate,@CommodityQuanlity,@unit,@Remark)
insert into dbo.TB_InventoryInfo(CommodityID,WarehouseID,Quantity,Unit)
values(@CommodityID,@WarehouseID,@CommodityQuanlity,@unit)
set @returnvalue=0
end
else
begin
update dbo.TB_InventoryInfo set Quantity=Quantity+@CommodityQuanlity where CommodityID=@CommodityID and WarehouseID=@WarehouseID
insert into dbo.TB_IncomInfo(CommodityID,WarehousePeople,WarehouseID,ArrivalDate,StorageDate,CommodityQuanlity,unit,Remark)
values(@CommodityID,@WarehousePeople,@WarehouseID,@ArrivalDate,@StorageDate,@CommodityQuanlity,@unit,@Remark)
set @returnvalue=0
end
以上就是我写的一个存数过程,别的地方都没问题,为什么insert into dbo.TB_InventoryInfo(CommodityID,WarehouseID,Quantity,Unit)
values(@CommodityID,@WarehouseID,@CommodityQuanlity,@unit)这一句每次运行后,都不能在数据库插入数据,
------解决方案--------------------
if @s=null
我觉得这句有问题,如果查询为空应该为@s is null
吧
------解决方案--------------------
1楼已经点明问题所在。
你这写法,第一个分支永远不会进去。