日期:2014-05-19  浏览次数:20522 次

高手替偶指点一下阿
有两张月份表
tab200702(str1   char(10),str2   char(10),...str15   char(10),DATE   char(10)),
tab200703(str1   char(10),str2   char(10),...str15   char(10),DATE   char(10)),字段是一样的,一共16个字段   ,根据选择条件去查询,如果选的是单个的月份就好办,可是如果夸月份怎么办呀?比如说查询条件是大于20070228,小于20070302。
注:DATE里   存的就是时间,格式为YYYYMMDD(如20070228)

如下写有问题:不能以   DISTINCT   方式选择   text、ntext   或   image   数据类型。
select   *   from   table200702   where   date> '20070228 '
union
select   *   from   table200703   where   date < '20070302 '


------解决方案--------------------
把 DATE 字段 cast(DATE as int) 来处理~~~

------解决方案--------------------
CAST((CONVERT(VARCHAR,ABS(DATEDIFF(MINUTE,GETDATE(),表字段)))) AS INT) <= 15
这句是时间相减取分钟小于等于15的,楼主可借鉴
------解决方案--------------------
select * from
(
select * from table200702
union all
select * from table200703
) t
where date> '2007-02-28 ' and date < '2007-03-02 '


select * from table200702 where date> '2007-02-28 '
union all
select * from table200703 where date < '2007-03-02 '