ALTER PROCEDURE spDisplayTableNames1
@T_ID INT OUT,
@BatchNumber VARCHAR(30) OUT
AS
BEGIN
IF((SELECT COUNT(*) FROM tblPacks
WHERE T_ID = @T_ID
AND BatchNumber = @BatchNumber) = 0)
AND ((SELECT COUNT(*) FROM tblBlisters
WHERE T_ID = @T_ID
AND BatchNumber = @BatchNumber) = 0)
AND ((SELECT COUNT(*) FROM tblShippers
WHERE T_ID = @T_ID AND BatchNumber = @BatchNumber) = 0)
BEGIN
PRINT '0 0 0'
END
ELSE IF((SELECT COUNT(*) FROM tblPacks WHERE [email protected]_ID AND [email protected])>0) AND ((SELECT COUNT(*) FROM tblBlisters WHERE [email protected]_ID AND [email protected])=0) AND ((SELECT COUNT(*) FROM tblShippers WHERE [email protected]_ID AND [email protected])=0)
BEGIN
Print '1 0 0'
END
ELSE IF((SELECT COUNT(*) FROM tblPacks WHERE [email protected]_ID AND [email protected])=0) AND ((SELECT COUNT(*) FROM tblBlisters WHERE [email protected]_ID AND [email protected])>0) AND ((SELECT COUNT(*) FROM tblShippers WHERE [email protected]_ID AND [email protected])=0)
BEGIN
Print '0 1 0'
END
ELSE IF((SELECT COUNT(*) FROM tblPacks WHERE [email protected]_ID AND [email protected])=0) AND ((SELECT COUNT(*) FROM tblBlisters WHERE [email protected]_ID AND [email protected])=0) AND ((SELECT COUNT(*) FROM tblShippers WHERE [email protected]_ID AND [email protected])>0)
BEGIN
Print '0 0 1'
END
ELSE IF((SELECT COUNT(*) FROM tblPacks WHERE [email protected]_ID AND [email protected])>0) AND ((SELECT COUNT(*) FROM tblBlisters WHERE [email protected]_ID AND [email protected])>0) AND ((SELECT COUNT(*) FROM tblShippers WHERE [email protected]_ID AND [email protected])=0)
BEGIN
Print '1 1 0'
END
ELSE IF((SELECT COUNT(*) FROM tblPacks WHERE [email protected]_ID AND [email protected])>0) AND ((SELECT COUNT(*) FROM tblBlisters WHERE [email protected]_ID AND [email protected])=0) AND ((SELECT COUNT(*) FROM tblShippers WHERE [email protected]_ID AND [email protected])>0)
BEGIN
Print '1 0 1'
END
ELSE IF((SELECT COUNT(*) FROM tblPacks WHERE [email protected]_ID AND [email protected])=0) AND ((SELECT COUNT(*) FROM tblBlisters WHERE [email protected]_ID AND [email protected])>0) AND ((SELECT COUNT(*) FROM tblShippers WHERE [email protected]_ID AND [email protected])>0)
BEGIN
Print '0 1 1'
END
ELSE IF((SELECT COUNT(*) FROM tblPacks WHERE [email protected]_ID AND [email protected])>0) AND ((SELECT COUNT(*) FROM tblBlisters WHERE [email protected]_ID AND [email protected])>0) AND ((SELECT COUNT(*) FROM tblShippers WHERE [email protected]_ID AND [email protected]tchNumber)>0)
BEGIN
Print '1 1 1'
END
END
這裏我檢查三個表的條件,如果一個列存在三個表中,它應該打印'1 1 1',如果它只存在於第一個和第三個表中,則打印' 1 0 1'。就像我寫了8條有條件的陳述。但我想要一個簡化的查詢上述存儲過程簡化If和else IF查詢
我想上面的例子最簡單的查詢 - 我該怎麼做?
我認爲這會給開頭的額外空間,例如「1 0 0」代替「1 0 0」 。但是,這可能很容易修復... – takrl
不會。它不會給空間作爲前綴。但空間將在最後。如果我們需要,我們可以刪除。然而尾隨空格不是問題 –
你是對的,這是一個尾隨空間,我誤解了代碼。或者可以通過LTRIM()或RTRIM()輕鬆修復... – takrl