空我有這個存儲過程:SQL Server存儲過程返回,而不是INTT
@upc AS VARCHAR(13) = NULL,
@cert_code AS VARCHAR(15) = NULL,
@vendor AS INT = NULL,
@count AS INT = 0 OUTPUT,
@store AS VARCHAR(3) = NULL,
@corporate AS VARCHAR = Null,
@zone AS VARCHAR = Null,
@region AS VARCHAR = Null,
@class AS VARCHAR = Null
AS
BEGIN -- Added for new functionality
SET NOCOUNT ON;
If @store IS NOT NULL
BEGIN
-- Get the storeID from Stores
DECLARE @storeID AS INT
SELECT @storeID = StoreID
FROM Enterprise..Stores
WHERE Store = @store
END
IF @storeID IS NOT NULL
BEGIN
IF @cert_code IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsStore
WHERE (StoreID = @storeID) AND (upc = @upc)
END
ELSE
BEGIN
IF @vendor IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsStore
WHERE (StoreID = @storeID) AND (cert_code = @cert_code)
END
ELSE
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsStore
WHERE (StoreID = @storeID)
AND (cert_code = @cert_code) AND (vendor = @vendor)
END
END
END
END
If @zone IS NOT NULL
BEGIN
IF @cert_code IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsZone
WHERE (upc = @upc)
END
ELSE
BEGIN
IF @vendor IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsZone
WHERE (cert_code = @cert_code)
END
ELSE
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsZone
WHERE (cert_code = @cert_code) AND (vendor = @vendor)
END
END
END
IF @region IS NOT NULL
BEGIN
IF @cert_code IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsRegion
WHERE (upc = @upc)
END
ELSE
BEGIN
IF @vendor IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsRegion
WHERE (cert_code = @cert_code)
END
ELSE
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsRegion
WHERE (cert_code = @cert_code) AND (vendor = @vendor)
END
END
END
IF @class IS NOT NULL
BEGIN
IF @cert_code IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsClass
WHERE (upc = @upc)
END
ELSE
BEGIN
IF @vendor IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsClass
WHERE (cert_code = @cert_code)
END
ELSE
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsClass
WHERE (cert_code = @cert_code) AND (vendor = @vendor)
END
END
END
IF @corporate IS NOT NULL
BEGIN
IF @cert_code IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsMaster
WHERE (upc = @upc)
END
ELSE
BEGIN
IF @vendor IS NULL
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsMaster
WHERE (cert_code = @cert_code)
END
ELSE
BEGIN
SELECT @count = COUNT(*)
FROM Enterprise..ProductsMaster
WHERE (cert_code = @cert_code) AND (vendor = @vendor)
END
END
END
GO
當我有@store IS NOT NULL
它計數及然而返回按預期的方式INT
,當@corporate
之一,@zone
,@region
,@class
被設置爲NOT NULL,我得到的輸出爲null,而不是像預期的INT。
這裏有什麼問題?
你在這裏有點太多了。你能否爲你的output = null情況下的每個變量傳遞一個參數值?我不確定有多少人在任何時候都是空的。 – Quantumplate
你也可以跟蹤哪些選擇語句是問題?也許用SELECT 999逐一替換它們,看它是否返回999而不是null?如果這沒有幫助,可以嘗試刪除位,直到你有一個較小的情況返回NULL,這樣我們可以將其中的一部分排除在外? – Quantumplate
如果你在開始時添加了SET @count = 0(在SET NOCOUNT ON之後),你的proc是否工作?你可能沒有'ELSE'分支在那裏撿起它 –