日期:2014-05-17 浏览次数:20508 次
select * from Question where (Id=(select case when Mid>0 then Mid else 29 end from Question as t2 where Id=29) or Mid=(select case when Mid>0 then Mid else 29 end from Question as t2 where Id=29)) and isnull(Reply,'')=''
select * from Question t
where exists(select 1 from Question as t2 where Id=29 and
case when Mid>0 then t.mid else t.id end= case when Mid>0 then Mid else 29 end)
and isnull(Reply,'')=''
WITH a1 AS
(
SELECT CASE WHEN Mid > 0 THEN Mid ELSE 29 END Mid FROM Question WHERE Id = 29
)
SELECT *
FROM Question a
JOIN a1 b ON a.id=b.mid OR a.mid=b.mid
WHERE ISNULL(a.Reply, '') = ''
WITH a1 AS
(
SELECT CASE WHEN Mid > 0 THEN Mid ELSE 29 END Mid FROM Question
WHERE Id = 29
)
SELECT *
FROM Question a
JOIN a1 b ON a.id=b.mid OR a.mid=b.mid
WHERE (a.Reply IS NULL OR a.Reply='')