0
我有一個包含一堆參數的存儲過程。他們永遠不會包含任何值,有些將是空的。在存儲過程中忽略基於空參數的語句
如果參數爲空,我該如何忽略這些插入語句?
使用firebug for firefox它告訴我,我的數據庫列不能包含空值,這就是爲什麼我相信我錯誤地編碼了這個存儲過程(我正在使用jQuery ajax和一個Web服務來與此存儲過程進行通信)。
ALTER PROCEDURE dbo.Vehicle_InsertAll
@Make varchar,
@Model varchar,
@SubModel varchar,
@Liter decimal,
@Cylinder varchar,
@Fuel varchar,
@FuelDel varchar,
@Asp varchar,
@EngDesg varchar
AS
IF @Make IS NOT NULL
BEGIN
INSERT INTO VehicleMakes (VehicleMake) VALUES(@Make)
END
IF @Model IS NOT NULL
BEGIN
INSERT INTO VehicleModels (Name) VALUES(@Model)
END
IF @SubModel IS NOT NULL
BEGIN
INSERT INTO VehicleSubModels (Name) VALUES(@SubModel)
END
IF @Liter IS NOT NULL
BEGIN
INSERT INTO VehicleLiters (Liters) VALUES(@Liter)
END
IF @Cylinder IS NOT NULL
BEGIN
INSERT INTO VehicleCylinders (Cylinders) VALUES(@Cylinder)
END
IF @Fuel IS NOT NULL
BEGIN
INSERT INTO VehicleFuel (FuelType) VALUES (@Fuel)
END
IF @FuelDel IS NOT NULL
BEGIN
INSERT INTO VehicleFuelDelivery (Delivery) VALUES (@FuelDel)
END
IF @Asp IS NOT NULL
BEGIN
INSERT INTO VehicleAspiration (Asp) VALUES (@Asp)
END
IF @EngDesg IS NOT NULL
BEGIN
INSERT INTO VehicleEngDesg (Designation) VALUES (@EngDesg)
END
RETURN
所以這個問題最終導致當我得到jQuery中的空白文本框的值並使用json傳遞給我的web服務時,json顯然沒有向web服務傳遞null值。 – 2010-11-18 10:02:43