SQL日历表数据的简单生成
为了公司考勤系统的需要
编写的几个简单存储过程(可以手动运行,也可以设置事务自动运行!感觉还行比较通用,写出来共享下)
Calendar表结构很简单,2个字段:
fdDate 日期
fdType 考勤类型(工作日N,周末W,节假日H[需要根据需要自己修改])
--判断一段时间范围内的工作日(N)和周末(W)
Create PROCEDURE [dbo].[NewMonthWeekDay_Calendar]
@sdate smalldatetime,
@edate smalldatetime
AS
declare @fdDate smalldatetime
declare @WeekDay varchar(20)
declare cr0 cursor for
select fdDate from calendar where fddate>=@sdate and fddate<=@edate
open cr0
fetch next from cr0 into @fdDate
while @@fetch_status=0
begin
if (datename(weekday,@fdDate)='星期一')
update calendar set fdType='N' where fdDate=@fdDate
if (datename(weekday,@fdDate)='星期二')
update calendar set fdType='N' where fdDate=@fdDate
if (datename(weekday,@fdDate)='星期三')
update calendar set fdType='N' where fdDate=@fdDate
if (datename(weekday,@fdDate)='星期四')
update calendar set fdType='N' where fdDate=@fdDate
if (datename(weekday,@fdDate)='星期五')
update calendar set fdType='N' where fdDate=@fdDate
if (datename(weekday,@fdDate)='星期六')
update calendar set fdType='W' where fdDate=@fdDate
if (datename(weekday,@fdDate)='星期日')
update calendar set fdType='W' where fdDate=@fdDate
fetch next from cr0 into @fdDate
end
close cr0
deallocate cr0
--根据年和月自动插入Calendar表新日期数据
Create PROCEDURE [dbo].[NewMonth_Calendar]
@Year int,
@Month int
AS
Select TOP 50 ID = Identity(Int, 0, 1) Into #T from SysColumns
insert into cas..calendar(fdDate)
Select Convert(Varchar(10), DateAdd(dd, ID, Cast(Rtrim(@Year) + '-' + Rtrim(@Month) + '-' + '01' As DateTime)), 120) from #T
W
相关文档:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BuildQuery
{
/// <summary>
/// 使用提供的数据建立一个SQL查询
/// </summary>
public class BuildQuery
{
#region 类的变量
int numFieldsCount, ......
下列语句部分是Mssql语句,不可以在access中使用。
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
1、说明:创建数据库
CREATE DATABASE data ......
本文主要讲述三个内容:
1.如何创建hierarychyid的表,插入数据及基本递归查询。
2.介绍hierarchyid的10种专有函数。
3.介绍hierarchyid特有的深度优先索引(Depth-First Indexing)和广度优先索引(Breadth-First Indexing)
在上一节中
http://blog.csdn.net/tjvictor/archive/2009/07/30/4395677.aspx
我们已经演 ......
LINQ to SQL 性能 10 Tips
http://www.cnblogs.com/worksguo/archive/2008/06/04/1213075.html
前一周,我的硬盘有两分区坏了,我准备的文章与资料都在里面,所以LINQ的文章停了一段时间,真的太不好拉,为来弥补一下就先发这篇文章上拉,明天再一篇关于Disconnection Data的文章。
只不过幸好,在这几天中我竭尽全力 ......