Append SQL table name with today’s date with SQL Query

I recently came across the following usefull SQL query, Maybe you’ll find it useful.
Create table with today’s date using SQL Query.


Query:

DECLARE @table varchar(500)
DECLARE @Q varchar(2000 )
SET @table='SQLTABLE_' +(CONVERT(VARCHAR(8),GETDATE(),112))
SET @Q= 'CREATE TABLE '+  @table + ' (Id int, Name [nvarchar](50) NULL)'
Exec(@Q)

Thanks

7 responses to “Append SQL table name with today’s date with SQL Query”

  1. HI, do u have any idea on Paypal integration with .net

    i need to used Dodirectpayment method of paypal . pls let me know if u have any idea.

  2. I am trying to schedule a query that will run against a new table that is created every day. The table is named “tableName20120725”. How can i write a query that can account for the table name changing?

Leave a Reply