数据库的outdate是char 如 2007年10月25日 2009年07月04日 都是这样的
我要在数据库里实现 between 2007-10-25 and 2009-05-01
这样导出hwouttb3insert into hwouttb3
select * from hwouttb where outdate between '2007年10月25日' and '2007年11月25日'and gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%'
union all
select * from hwouttb2 where outdate between '2007年10月25日' and '2007年11月25日'and gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%'刚才有个兄弟写了个
没有在between and范围内insert into hwouttb3
select * from hwouttb where
CAST(REPLACE(REPLACE(REPLACE(outdate,'年','-' ),'月','-'),'日','') AS DATETIME)
between
CAST(REPLACE(REPLACE(REPLACE('2007年10月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and
CAST(REPLACE(REPLACE(REPLACE('2007年11月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%'
union all
select * from hwouttb2 where
CAST(REPLACE(REPLACE(REPLACE(outdate,'年','-' ),'月','-'),'日','') AS DATETIME)
between
CAST(REPLACE(REPLACE(REPLACE('2007年10月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and
CAST(REPLACE(REPLACE(REPLACE('2007年11月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%'
我要在数据库里实现 between 2007-10-25 and 2009-05-01
这样导出hwouttb3insert into hwouttb3
select * from hwouttb where outdate between '2007年10月25日' and '2007年11月25日'and gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%'
union all
select * from hwouttb2 where outdate between '2007年10月25日' and '2007年11月25日'and gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%'刚才有个兄弟写了个
没有在between and范围内insert into hwouttb3
select * from hwouttb where
CAST(REPLACE(REPLACE(REPLACE(outdate,'年','-' ),'月','-'),'日','') AS DATETIME)
between
CAST(REPLACE(REPLACE(REPLACE('2007年10月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and
CAST(REPLACE(REPLACE(REPLACE('2007年11月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%'
union all
select * from hwouttb2 where
CAST(REPLACE(REPLACE(REPLACE(outdate,'年','-' ),'月','-'),'日','') AS DATETIME)
between
CAST(REPLACE(REPLACE(REPLACE('2007年10月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and
CAST(REPLACE(REPLACE(REPLACE('2007年11月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%'
解决方案 »
- 重复行的列显示Null,数据库2000
- 领教了SQL的查找速度。不知道哪位大侠还能让SQL更快。高分求问
- 数据设计问题
- 请教个sql 问题! 在sql中做除法时,判断除数为零,想在一条语句中实现!
- 调用.sql文件有没有比较好的参数传递方法?
- 大家帮帮忙很急。。。。。。。。。。
- 请教,关于高频率读写数据库
- 求各位大哥帮解一个distinct部分字段
- ADO调用存贮过程中用text为参数时报,"字符串数据右截位",请求如何解决,
- begin tran再使用远程查询和BEGIN DISTRIBUTED TRANSACTION都是分布式事务吗?有什么区别?用OPENDATASOURCE('MSDASQL'和SQLOLEDB'区别?相
- sql语句获取记录数
- java连接SQL2005的问题
直接把天数加一天,或用DATEFIFF
输入来的数据有2008年的数据和2009的数据还有些2007不是我条件的数据!
use kiaqew
/*create table rq
(sid char(10),
srq varchar(15)
)
go
insert into rq values('1','2006年10月25日');
insert into rq values('2','2005年10月25日');
insert into rq values('3','2007年11月25日');
insert into rq values('4','2007年1月25日');
insert into rq values('5','2007年9月25日');
insert into rq values('6','2007年2月25日');
insert into rq values('7','2007年3月25日');
insert into rq values('8','2007年5月25日');
insert into rq values('10','2007年6月25日');
*/
select CAST(REPLACE(REPLACE(REPLACE(srq,'年','-' ),'月','-'),'日','') AS DATETIME) as rqtime,* into #kkkk from rq
select * from #kkkk where rqtime between '2007-1-1' and '2007-12-1'可以成功。。学习了。。replace ..哈
CAST(REPLACE(REPLACE(REPLACE(outdate,'年','-' ),'月','-'),'日','') AS DATETIME)
between
CAST(REPLACE(REPLACE(REPLACE('2007年10月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and
CAST(REPLACE(REPLACE(REPLACE('2007年10月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and (gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%')
union all
select * from hwouttb2 where
CAST(REPLACE(REPLACE(REPLACE(outdate,'年','-' ),'月','-'),'日','') AS DATETIME)
between
CAST(REPLACE(REPLACE(REPLACE('2007年10月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and
CAST(REPLACE(REPLACE(REPLACE('2007年10月25日','年','-' ),'月','-'),'日','') AS DATETIME)
and (gysh like '%生產%' or gysh like '%工程%' or gysh like '%倉庫%')