Tuesday, 30 September 2014

how to create tablename dynamically in SQL server

Write this quary and get table name  append with current date


CREATE proc createtable
as
begin
DECLARE @SQLString NVARCHAR(MAX)
SET @SQLString = 'CREATE TABLE Tab_'+convert(varchar,getdate(),112) + '( id bigint,name varchar(200))'
 EXEC sp_executesql @SQLString
 end

No comments:

Post a Comment