如写成固定语句可以这样写:
select opdate from 表 A where
exists (select opdate from 表 where opdate=dateadd(Day,1,A.opdate))
and exists (select opdate from 表 where opdate=dateadd(Day,2,A.opdate))
and exists (select opdate from 表 where opdate=dateadd(Day,3,A.opdate))
and exists (select opdate from 表 where opdate=dateadd(Day,4,A.opdate))
and exists (select opdate from 表 where opdate=dateadd(Day,5,A.opdate))
and exists (select opdate from 表 where opdate=dateadd(Day,6,A.opdate))
and exists (select opdate from 表 where opdate=dateadd(Day,7,A.opdate))
and exists (select opdate from 表 where opdate=dateadd(Day,8,A.opdate))
and exists (select opdate from 表 where opdate=dateadd(Day,9,A.opdate))
order by opdate
declare @n as int
declare @max_n as int
declare @sqlstr as varchar(8000)
select @max_n=10
select @n=1
select @sqlstr=''
while(@n<@max_n)
begin
select @sqlstr=@sqlstr + ' and exists (select opdate from 表 where opdate=dateadd(Day,'+ cast(@n as varchar(10)) +',A.opdate))'
select @n=@n+1
end
select @sqlstr='select opdate from 表 A where' + @sqlstr+' order by opdate'
select @sqlstr=Replace(@sqlstr,'where and','where')