惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

博客园 - Pvistely

怀旧下给自己留个备份, 小东西WinForm的等待窗口 FluorineFx ASObject自动转换基础类 AutoParseASObject ,用于Flash AMF协议解析 PPPOE数据包转换及SharpPcap应用 Flash网页游戏辅助工具制作简析 Microsoft SQL Server 2008 基本安装说明 SQL 2000 异数据库数据同步 请把这个消息提示框拿掉,谢谢 MS新版Wallop, 被VB6搞死。。。。。。。鸟 企业管理应用系统平台插件接口应用说明 企业管理应用系统平台应用说明 企业管理应用平台预览演示版下载 企业管理系统应用平台(预览版) ENA13条码转换函数 运行时自定义PropertyGrid显示属性项目 C1Flexgrid与XtraGrid性能比较 继上次的GDI+做报表设计器后............. 想用GDI+2.0做设计器,但在实现过程中遇到大麻烦
SQL查询日历
Pvistely · 2015-10-02 · via 博客园 - Pvistely

 这东西给自己留着用。

经常会用到一些查询需要做全月统计,但有些时候的统计需要将未发生日期也显示出来,因此会需要一个固定的日期表,(T6的自定义查询估计也是需要的,至少以前是这样)

下面写两种方法来获取指定月份的日期表,第一种适用SQL 2000及以上版本的数据库,第二种只适用SQL 2005及以上版本数据库

函数一:

--支持SQL 2000

CREATE FUNCTION dbo.GetCalendar(@Begin NVARCHAR(30))

RETURNS @rst TABLE(dDate SMALLDATETIME,iDx int IDENTITY(1,1) NOT NULL)

AS

BEGIN

    IF ISNULL(@Begin,'')='' RETURN

    INSERT INTO @rst

    SELECT TOP (DATEDIFF(DAY,@Begin,DATEADD(MONTH,1,@Begin)-1)+1) @Begin

    FROM syscolumns

    UPDATE @rst SET dDate=dDate+iDx-1  

    RETURN

END

GO

使用方法:

SELECT * FROM dbo.GetCalendar('2015-6-1') 

函数二:

--需要ROW_NUMBER函数的支持,支持SQL 2005及以上版本数据库

CREATE FUNCTION dbo.GetCalendar2005(@Begin NVARCHAR(30))

RETURNS @rst TABLE(dDate SMALLDATETIME)

AS

BEGIN

    INSERT INTO @rst

   SELECT TOP (DATEDIFF(DAY,@Begin,DATEADD(MONTH,1,@Begin)-1)+1) CAST(@Begin AS SMALLDATETIME)-1+ROW_NUMBER() OVER(ORDER BY ID)

    FROM

    syscolumns

    RETURN

END

GO

使用方法:

SELECT * FROM dbo. GetCalendar2005('2015-6-1')