首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

状态历史的有关问题

2012-02-23 
状态历史的问题状态历史表StatusHistory有Status,TransactionId,AsofDate.Status的取值范围包括(1,2,3,4).

状态历史的问题
状态历史表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)

热点排行
Bad Request.