请教:存储过程中,参数可变的情况?
如果需要将@Name和@Price的值设为null插入数据库,请问下面代码会出错吗,如果会请问应该怎样修改呢?
CREATE PROCEDURE ST_InsertRoomCategory
(@Name varchar(50),@Area float,
@BedNum int, @Price money,
@AirCondition int,
@TV int)
AS
insert into ST_RoomCategory
( ST_Name,ST_Area,ST_BedNum,ST_Price,ST_AirCondition,ST_TV)
values
( @Name,@Area,@BedNum,@Price,@AirCondition,@TV)
GO
------解决方案----------------------try
CREATE PROCEDURE ST_InsertRoomCategory
(
@Name varchar(50)=null,
@Area float,
@BedNum int,
@Price money=null,
@AirCondition int,
@TV int
)
AS
insert into ST_RoomCategory
( ST_Name,ST_Area,ST_BedNum,ST_Price,ST_AirCondition,ST_TV)
values
( @Name,@Area,@BedNum,@Price,@AirCondition,@TV)
GO