易截截图软件、单文件、免安装、纯绿色、仅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查询每行中最大值的技巧

--------------------------------------------------------------------------
--  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中一些特别地方的特别解法

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 ......

解密SQL SERVER 2005加密存储过程,函数


在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 ......

sql日期转换参数

sql日期转换参数
--日期转换参数,值得收藏
select CONVERT(varchar, getdate(), 120)
2004-09-12 11:06:08
select convert(varchar(10),getdate() ,120) 
----------
2009-04-09
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
20040912110608
select CONVERT( ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号