CASE WHEN, . ( )
Select * From Table1
Where
CASE @Chk
WHEN 'Y' THEN
CASE WHEN Column1=@Value THEN 1 END
WHEN 'N' THEN
CASE WHEN Column1 In (Select column2 from Table2) THEN 1 END
END = 1
CASE .
, OR: http://www.sqlfiddle.com/#!6/29531/2
:
select count(*)
from usermessages um
join "user" u
on
(case when um.friendId = 1 then um.sourceUserId else um.friendId end) = u.userId;
select count(*)
from usermessages um
join "user" u
on
(um.friendId = 1 and um.sourceUserId = u.userId)
or
(um.friendId = u.userId);
http://www.sqlfiddle.com/#!6/29531/2, 88 , 4,7 . .
, , . CASE WHEN - ( ). - ,