我在存储过程中有以下语句:
INSERT INTO @tblThreatenedSpeciesSubzone
(ThreatenedSpeciesZoneID,
ManagementZoneID,
VegetationZoneID)
SELECT *
FROM OPENXML (@hDoc, '/NewDataSet/tblThreatenedSpeciesSubzone', 2)
WITH (ThreatenedSpeciesZoneID INT,
ManagementZoneID INT,
VegetationZoneID INT) XMLDATA
WHERE VegetationZoneID = @VegetationZoneIDInXML
有时" managementZone id"变为null,我想替换它是否为null然后我想传递常量值" 0"。有办法吗?
答案 0 :(得分:2)
不确定"传递常数值",但您始终可以设置默认值:
CREATE PROCEDURE Sales.uspGetSalesYTD
@SalesPerson nvarchar(50) = 'Andersson' -- default value
AS
所以:
@ManagementZoneID INT = 0
答案 1 :(得分:0)
您可以在select语句中使用coalesce
INSERT INTO @tblThreatenedSpeciesSubzone
( ThreatenedSpeciesZoneID ,
ManagementZoneID ,
VegetationZoneID
)
SELECT
ThreatenedSpeciesZoneID ,
COALESCE(ManagementZoneID,0) ,
VegetationZoneID
FROM OPENXML (@hDoc, '/NewDataSet/tblThreatenedSpeciesSubzone', 2)
WITH ( ThreatenedSpeciesZoneID INT ,
ManagementZoneID INT ,
VegetationZoneID INT ) XMLDATA
WHERE VegetationZoneID = @VegetationZoneIDInXML