日期:2014-05-18  浏览次数:20732 次

状态历史的问题
状态历史表StatusHistory有Status,TransactionId,AsofDate.Status的取值范围包括(1,2,3,4).现在要查到某个日期比如2007-7-31   Status为1,2或者3的数据.
一个TransactionId会有多个Status不用游标能实现吗?

------解决方案--------------------
--这样?
select * from tablename where status in(1,2,3) and AsofDate = '2007-7-31 '
------解决方案--------------------
表中数据是什么样子?
------解决方案--------------------
?


Select * From StatusHistory
Where Status In (1,2,3,4) And DateDiff(dd, AsofDate, '2007-7-31 ') = 0
------解决方案--------------------
要查到某个日期比如2007-7-31 Status为1,2或者3的数据.
------------------------------------------------
楼主是指状态一直保持1/2/3其中的一种且不变化?

如果是这样,那么

select
s.*
from
StatusHistory s
where
s.Status in(1,2,3)
and
datediff(dd,s.AsofDate, '2007-07-31 ')=0
and
not exists(select 1 from StatusHistory where Status!=s.Status and datediff(dd,AsofDate,s.AsofDate)=0)