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
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BuildQuery
{
/// <summary>
/// 使用提供的数据建立一个SQL查询
/// </summary>
public class BuildQuery
{
#region 类的变量
int numFieldsCount, ......
在SQL优化过程中常见Oracle HINT的用法:
1. /*+ALL_ROWS*/
表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化.
例如:
SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN from BSEMPMS WHERE EMP_NO='SCOTT';
2. /*+FIRST_ROW ......
PowerBuilder是目前最流行的数据库开发工具之一。PowerBuilder提供了在程序代码中加入嵌入式SQL语句的功能来支持对数据库的访问。但这种嵌入式SQL语句只能支持一些固定的标准的SQL语句,即在进行程序代码编译处理时这些SQL语句必须是确定的,例如:对哪张表哪几个字段进行操作在程序代码中是固定写明的,另外这种方式也不能 ......
随着B/S模式应用开发的发展,使用这种模式编写应用程序的程序员也越来越多。但是由于程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候,没有对用户输入数据的合法性进行判断,使应用程序存在安全隐患。用户可以提交一段数据库查询代码,根
据程序返回的结果,获得某些他想得知的数据,这就是所谓的SQ ......