Create Proc [dbo].[PN_CreateHistoryDataTable]
AS
Begin
Declare @Count int
Declare @CollCode varchar(4)
Declare @TableName varchar(30)
Declare @StrSql nvarchar(2000)
Declare @CreateSQL varchar(2000)
Declare CurColliery Cursor For Select CollCode From TN_Colliery
Open CurColliery
Fetch Next From CurColliery Into @CollCode
While @@fetch_status=0
Begin
Set @TableName = 'TN_Data' + @CollCode + Replace(Replace(Replace(Convert(varchar, GetDate(), 112 ),'-',''),' ',''),':','')
Set @StrSql=N'Select @InsideCount=Count(*) From SysObjects Where Id = object_id('''+ @TableName +''') And Type = ''U'''
Exec Sp_ExecuteSQL @StrSql ,N'@InsideCount int output',@Count output