這是一個查詢。 Where
子句包含兩個部分,它們都是假的(因爲@Notify不等於13005或13105)。如何查詢一個錯誤的「where」條件返回結果?
但是這個查詢返回36行。如果block包含false,它如何返回任何東西? CHECKDB顯示沒有錯誤,重啓也沒有幫助。如果我添加1 = 0條件而不是@Notify = 13005,則查詢返回0行。
SQL Server版本 - 微軟的SQL Server 2008(RTM) - 10.0.1600.22 (英特爾X86) 2008年7月9日14時43分34秒 版權所有(C)1988-2008微軟公司 Express Edition與高級在Windows NT 6.1服務(建設7601:Service Pack 1的)(WOW64)
declare @Notify smallint
set @Notify = 20
select distinct DMD_ID
,cast(DMD_Document as varchar) + '-' + cast(Cl_Place as varchar) as DMD_Document
,DMD_Client
from DocMoveDemand
inner join Client on DMD_Client = Cl_ID
inner join DocMoveDemandList on DMDL_SDoc = DMD_ID
left outer join DocOut on DO_DocMoveDemand = DMD_ID
where (
@Notify = 13005
and DMDL_DocMoveDenyReason in (2,3,4)
and (
DO_IsMove = 'Y'
or DMD_IsReturn = 1
)
and DateDiff(DD, isnull(DMD_DateReturn, DO_DateMove), GETDATE()) < 14
and DMD_NotifyInv1 = 0
)
or (
@Notify = 13105
and DMDL_DocMoveDenyReason in (2,3,4)
and (
DO_IsMove = 'Y'
or DMD_IsReturn = 1
)
and DateDiff(DD, isnull(DMD_DateReturn, DO_DateMove), GETDATE()) >= 14
and DMD_NotifyInv2 = 0
)
order by DMD_ID
這裏是直接比較https://www.brentozar.com/pastetheplan/?id=S1hTRr59W與(SELECT @Notify)
https://www.brentozar.com/pastetheplan/?id=Hk27lI9cW
請後執行計劃https://www.brentozar.com/pastetheplan/ – lad2025
嘗試改變'@Notify = 13005'到'(SELECT @Notify)= 13005'和相同的第二。 – lad2025
@ lad2025增加了計劃以 – ventik