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

sql中日期格式

1 ---上个月月初第一天
  2  select CONVERT(varchar(12) , DATEADD(mm,DATEDIFF(mm,0,dateadd(mm,-1,getdate())),0), 112 )
  3
  4  ---上个月月末最后一天
  5  select CONVERT(varchar(12),dateadd(ms,-3,DATEADD(mm,DATEDIFF(m,0,getdate()),0)), 112 )
  6
  7  --1. 显示本月第一天
  8  
  9  SELECT DATEADD(mm,DATEDIFF(mm,0,getdate()),0)
10
11 select convert(datetime,convert(varchar(8),getdate(),120)+'01',120)
12
13 --2. 显示本月最后一天
14
15 select dateadd(day,-1,convert(datetime,convert(varchar(8),dateadd(month,1,getdate()),120)+'01',120))
16
17 SELECT dateadd(ms,-3,DATEADD(mm,DATEDIFF(m,0,getdate())+1,0))
18
19 --3. 上个月的最后一天
20
21 SELECT dateadd(ms,-3,DATEADD(mm,DATEDIFF(mm,0,getdate()),0))
22
23 --4. 本月的第一个星期一
24 select DATEADD(wk,DATEDIFF(wk,0, dateadd(dd,6-datepart(day,getdate()),getdate())),0)
25
26 --5. 本年的第一天
27
28 SELECT DATEADD(yy,DATEDIFF(yy,0,getdate()),0)
29
30 --6. 本年的最后一天
31
32 SELECT dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,getdate())+1,0))
33
34 --7. 去年的最后一天
35
36 SELECT dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,getdate()),0))
37
38 --8. 本季度的第一天
39
40 SELECT DATEADD(qq,DATEDIFF(qq,0,getdate()),0)
41
42 --9. 本周的星期一
43
44 SELECT DATEADD(wk,DATEDIFF(wk,0,getdate()),0)
45
46 --10. 查询本月的记录
47
48 select * from tableName where DATEPART(mm, theDate)=DATEPART(mm, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
49
50 --11. 查询本周的记录
51
52 select * from tableName where DATEPART(wk, theDate) = DATEPART(wk, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
53
54 --12 查询本季的记录 注:其中:GETDATE() 是获得系统时间的函数。
55
56 select * from tableName where DATEPART(qq, theDate) = DATEPART(qq, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
57
58 --13. 获取当月总天数:
59
60 select DATEDIFF(dd,getdate(),DATEADD(mm, 1, getd


相关文档:

测试人员要掌握的基本的SQL语句(上)

测试人员要掌握的基本的SQL语句(上)
 
 
 
 
                                        ......

SQL Server之分布式事务

SQL Server之分布式事务
 
 收藏
--> Title  : SQL Server之分布式事务
 
--> Author : wufeng4552
 
--> Date   : 2009-11-11
 
SQL Server之分布式事务
 
(一)概念:
 
分布式事务是涉及来自两个或多个源的资源的事务。Microsoft® SQL Serv ......

sql 游标的使用

一个例子:从tszl表中查出数据,根据cs字段的值决定往BOOK_SERIAL表中插入几行数据。
declare @num int
declare @id varchar(60)
declare @classbm varchar(60)
set @classBm='101'
declare id cursor for select id,cs from  [tszl]
open id
fetch next from id into @id,@num
while @@fetch_status!=-1
&nb ......

How to use PL SQL Developer in Ubuntu

You can user PL SQL Developer in Ubuntu like in Windows:
1.download PL/SQL Developer for linux;
2.Install JDK berfore the next;
3.install the PL/SQL Developer;
4.goto the $PL/SQL Developer,run sh sqldeverloper.sh;
5.type the $JDK;
6.then the PL/SQL Developer will startup. ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号