SQL_查询当天、近几天、本周、本月的SQL语句
经常会有时候要用到查询当天,近几天,本周,本月的相关数据,所以记录一下这些比较特殊的SQL语句~~
--当天
(usrRegTime >=CONVERT(varchar(10),getDate(),120)+' 00:00:00' and usrRegTime <=CONVERT(varchar (10),getDate(),120)+' 23:59:59')
--近三天
DateDiff(day,usrRegTime,getdate()) <=3
--本周
Datepart(year,usrRegTime)=DatePart(year,Getdate()) and DatePart(week,usrRegTime)=DatePart (week,GetDate())
--本月
Datepart(year,usrRegTime)=DatePart(year,Getdate()) and DatePart(month,usrRegTime)=DatePart (month,GetDate())
相关文档:
/*
建表:
dept:
deptno(primary key),dname,loc
emp:
empno(primary key),ename,job,mgr,sal,deptno
*/
1 列出emp表中各部门的部门号,最高工资,最低工资
select max(sal) as 最高工资,min(sal) as 最低工资,deptno from emp group by deptno;
2 列出emp表中各部门job为'CLERK'的员工的最低工资,最高工资
sele ......
由于工作和学习的需要,要在本本上安装SQL SERVER 2005 开发版(本本的操作系统是XP,所以不能安装Enterprise版本,而Express版本的功能又十分有限),去微软的官方网站搜索了一下sql server 2005 developer,找到了一些关于Sql server各种版本的介绍,首先sql server 2005有以下几种版本: EE = SQL Server 2005 Enterprise ......
The following is improved version of the code created by David Mullet, from
http://rubyonwindows.blogspot.com/2007/03/ruby-ado-and-sqlserver.html
require 'win32ole'
class SqlServer
# This class manages database connection and queries
attr_accessor :connection, :data, :fields
attr_wr ......
我们在开发过程中,经常遇到这样问题,就是要求定期进行数据库的检查,如果发现特定数据,那么就要进行某项操作,这个需求呢,可以利用Windows的计划任务,定期执行某一个应用程序,去检索数据;也可以让程序自己控制。其实SQL Server自己也可以创建计划任务,定期进行执行。如果数据库服务器允许,可以考虑采用这种方式。
......