-- Variable that will contain the name
of the table
declare @mytable varchar(100)
-- Creates a temp table name
select @mytable = 'Table_'
+ CAST(DATEPART(yy, GETDATE()) as nvarchar(10)) + CAST(DATEPART(mm, GETDATE()) as nvarchar(10)) + CAST(DATEPART(dd, GETDATE()) as nvarchar(10))
+ CAST(DATEPART(hh, GETDATE()) as nvarchar(10)) + CAST(DATEPART(mi, GETDATE()) as nvarchar(10)) + CAST(DATEPART(ss, GETDATE()) as nvarchar(10))
print @mytable
-- Create the temporary table
execute ('create table DatabaseName.dbo.'+
@mytable +
'(
[Date]
[datetime] NULL,
[CustomerId]
[int] NULL
[Status]
[tinyint] NULL,
[LastUpdate]
[datetime] NULL
)' )
-- Insert two rows
in the table
execute ('insert into
DatabaseName .dbo.' +
@mytable +
' ([Date]
,[CustomerId]
,[Status]
,[LastUpdate])
SELECT [Date]
,[FeatureId]
,[Status]
,[LastUpdate]
FROM [dbo].[
Table ]')
No comments:
Post a Comment