易截截图软件、单文件、免安装、纯绿色、仅160KB

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
--随后七天


相关文档:

更改SQL 2005的登陆方式

如果你的身份验证方式为Windows集成身份验证更改为混合方式的身份验证,需要在SQL Server Configuration Management中,把TCP/IP的活动启用,也就是第一个选择的地方,选择启用。并且使用集成身份验证方式登录后,在数据库服务器上选择属性,把安全性下的WINDOWS模式改为SQL与WINDOWS模式 ......

SQL查询每行中最大值的技巧

--------------------------------------------------------------------------
--  Author : htl258(Tony)
--  Date   : 2010-04-23 08:08:36
--  Version:Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
--          Jul  ......

SQL函数调用

函数如下
CREATE FUNCTION StockBalance_AmountIn(@SortID int)  
 RETURNS numeric(18,4)
AS  
BEGIN 
 Declare @dblReturn numeric(18,4)
 Select @dblReturn = SUM(AmountCurrentMonthIn) from AT_Materiel_StockBalance Where SortID = @SortID
 Return (@dblReturn)
END
......

SQL SERVER中一些特别地方的特别解法

SQL code
/*----------------------------------------------------------------
-- Author :feixianxxx(poofly)
-- Date :2010-04-20 20:10:41
-- Version:
-- Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (Intel X86)
Mar 29 2009 10:27:29
Copyright (c) 1988-2008 Microsoft Co ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号