sql语句获取本周、上一周、本月数据
本周
select * from tb where datediff(week , 时间字段 ,getdate()) = 0
上周
select * from tb where datediff(week , 时间字段 ,getdate()) = 1
下周
select * from tb where datediff(week , 时间字段 ,getdate()) = -1
----------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
--上月
Select * from TableName Where DateDiff(mm, DateTimCol, GetDate()) = 1
--本月
Select * from TableName Where DateDiff(mm, DateTimCol, GetDate()) = 0
--下月
Select * from TableName Where DateDiff(mm, GetDate(), DateTimCol ) = 1
昨天:dateadd(day,-1,getdate())
明天:dateadd(day,1,getdate())
上月:month(dateadd(month, -1, getdate()))
本月:month(getdate())
下月:month(dateadd(month, 1, getdate()))
---------------------------------------------------------------------------------
--昨天
Select * from TableName Where DateDiff(dd, DateTimCol, GetDate()) = 1
--明天
Select * from TableName Where DateDiff(dd, GetDate(), DateTimCol) = 1
--最近七天
Select * from TableName Where DateDiff(dd, DateTimCol, GetDate()) <= 7
--随后七天
相关文档:
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
fr ......
----------------------------------------------------------------------
1、SQL数据库恢复模型
----------------------------------------------------------------------
1)完全恢复模型
-----------------
(1)备份时要备份数据库的数据文件和日志文件
(2)还原时使用数据库的备份的数据文件副本和全部日志信 ......
--------------------------------------------------------------------------
-- Author : htl258(Tony)
-- Date : 2010-04-23 08:08:36
-- Version:Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
-- Jul  ......
在SQL SERVER 2005中必须用专用管理连接才可以查看过程过程中用到的表
EG:sqlcmd -A
1>use test
2>go
1>sp_decrypt 'p_testa'
2>go
Text
----------------------
Create procedure P_testa
with encryption
as
select * from test
create PROCEDURE [dbo].[sp_decrypt]
(@procedure s ......