1
這是我以前的帖子的修改版本。請幫我解決一下這個。 如果子查詢我得到正確的結果。但是當我運行完全SP警報案例和現場案件相互覆蓋。存儲過程Case語句互相覆蓋
Getting null value in status field, can anyone explain what I am going wrong?
(CASE
WHEN EXISTS(SELECT [GunSerialNo] FROM [dbo].[ArmouryIssueGun]
WHERE aig.ModifiedOn IS NOT NULL
AND aig.CreatedOn IS NOT NULL)
THEN 'In Armory'
WHEN EXISTS(SELECT aig.GunSerialNo
FROM [dbo].[ArmouryIssueGun] AS aig
INNER JOIN (SELECT *
FROM
(SELECT GunSerialNo, DATEADD(HOUR, EstimatedTime, CreatedOn) AS TIME_ADDED
FROM [ArmouryIssueGun]) ag
WHERE ag.TIME_ADDED<GETUTCDATE()) abd ON abd.GunSerialNo = aig.GunSerialNo
WHERE aig.ModifiedOn IS NULL
AND aig.CreatedBy IS NOT NULL)
THEN 'Alert'
WHEN EXISTS (SELECT aig.GunSerialNo
FROM [dbo].[ArmouryIssueGun] AS aig
INNER JOIN (SELECT *
FROM
(SELECT GunSerialNo, DATEADD(HOUR, EstimatedTime, CreatedOn) AS TIME_ADDED
FROM [ArmouryIssueGun]) ag
WHERE ag.TIME_ADDED>GETUTCDATE()) abd ON abd.GunSerialNo = aig.GunSerialNo
WHERE aig.ModifiedOn IS NULL
AND aig.CreatedBy IS NOT NULL)
THEN 'In Field'
END) AS [Status],
FROM
[dbo].[CarryAndUseLicence] cl
INNER JOIN
[dbo].[Branch] b ON b.[BranchId] = cl.[BranchId]
INNER JOIN
[dbo].[Gun] gun ON cl.[GunSerialNo] = gun.[SerialNo]
INNER JOIN
[dbo].[ArmouryIssueGun] aig ON aig.[StaffId] = cl.[StaffId]
嘗試用一個有效的結果替換所有子查詢和運行的程序,檢查它是否工作正常 –