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
--随后七天
相关文档:
首先得下载驱动程序到微软网站下载Microsoft SQL Server 2005 JDBC Driver 1.2
解压Microsoft SQL Server 2005 jdbc driver1.2.exe,把sqljdbc_1.1复制到%ProgramFiles%(如果系统在C盘则为C:\Program Files)。
设置 Classpath
JDBC 驱动程序并未包含在 Java SDK 中。因此,如果要使用该驱动程序,必须将 classpath ......
函数如下
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 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中必须用专用管理连接才可以查看过程过程中用到的表
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 ......