USE [UMoney] GO /****** Object: StoredProcedure [dbo].[WCL_WorkerStatDailyWrite] Script Date: 10/08/2013 14:28:26 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ------------------------------------ --用途:根据日期生成用户个人信息日统计表并插入数据 --王朝理 --时间:2013/10/6 18:02:53 ------------------------------------ ALTER proc [dbo].[WCL_WorkerStatDailyWrite] @WorkerID bigint as begin tran set nocount on declare @tb_name nvarchar(100),@sql nvarchar(1000) declare @cou int -- 表的名称 set @tb_name='WorkerStatDaily'+REPLACE(CONVERT(VARCHAR(10),GETDATE(),120),'-','') -- 如果表不存在,就建立表 if not exists(select 1 from sysobjects where name=@tb_name and xtype='U') begin set @sql='create table dbo.['+@tb_name+']([ID] [bigint] IDENTITY (1, 1) NOT NULL, [WorkerID] [bigint] NULL, [StatDate] [datetime] NULL, [FinishedTask] [int] NULL, [NewTaskCount] [int] NULL, [GetPoint] [int] NULL, [SubWorkers] [int] NULL, [OnlineHours] [int] NULL, [SignFlag] [int] NULL)' --print @sql exec(@sql) end set @sql= N'select top 1 @WorkerID2=WorkerID from ['+@tb_name+'] where WorkerID=@WorkerID and DATEDIFF(day,StatDate,GETDATE())=0' exec sp_executesql @sql, N'@WorkerID2 int out,@WorkerID bigint', @cou out ,@WorkerID IF ISNULL(@cou,'')='' BEGIN set @sql='insert into ['+@tb_name+'] values ('+convert(varchar,@WorkerID)+','''+convert(varchar,GETDATE())+''',0,0,0,0,0,0)' exec(@sql) END set nocount off commit tran