बस एक छोटे से adjustement जो लोग बाद में आते हैं Fors:
समानता ऑपरेटर एक unknow मूल्य उत्पन्न जब वहाँ एक अशक्त है और अज्ञात मूल्य एक झूठी व्यवहार किया जाता है। नहीं (अज्ञात) अज्ञात है
नीचे दिए गए उदाहरण में मैं यह कहने की कोशिश करूंगा कि कोई जोड़ा (ए 1, बी 1) बराबर है (ए 2, बी 2)। ध्यान दें कि प्रत्येक कॉलम में 3 मान 0, 1 और न्यूल हैं।
DECLARE @t table (a1 bit, a2 bit, b1 bit, b2 bit)
Insert into @t (a1 , a2, b1, b2)
values(0 , 0 , 0 , NULL)
select
a1,a2,b1,b2,
case when (
(a1=a2 or (a1 is null and a2 is null))
and (b1=b2 or (b1 is null and b2 is null))
)
then
'Equal'
end,
case when not (
(a1=a2 or (a1 is null and a2 is null))
and (b1=b2 or (b1 is null and b2 is null))
)
then
'not Equal'
end,
case when (
(a1<>a2 or (a1 is null and a2 is not null) or (a1 is not null and a2 is null))
or (b1<>b2 or (b1 is null and b2 is not null) or (b1 is not null and b2 is null))
)
then
'Different'
end
from @t
नोट हम उम्मीद करते हैं कि यहाँ के परिणाम:
- अशक्त
- बराबर नहीं होने के लिए समान नहीं बराबर
- अलग
लेकिन हम प्राप्त होने के लिए विभिन्न एक और परिणाम
- बराबर ठीक है
- बराबर नहीं है ???
- अलग अलग है
स्रोत
2010-05-20 15:25:54
भी देखें: http://stackoverflow.com/questions/723195/should-i-use-or-for-not-equal-in-tsql – Dinah