The alert is being generated because you have Quoted Identifiers off when you are running it.
Remove the double quotes and replace them with square brackets. In SQL Server the double quote isn’t the default separator. This would make your code look more like this.
<pre>DECLARE @tblName varchar(30) SET @tblName = CONVERT(VARCHAR(20),GETDATE(),112) + ‘Table’
DECLARE @sql nvarchar(4000) SELECT @sql = ‘CREATE TABLE [‘ + @tblName + ‘] ( ID VARCHAR(15), Name VARCHAR(15) )’
It is a very bad practice to use a single table per day, as your system maintenance will become very unwieldy very quickly.
Hi Mr Denny,
Thanks very much for the solution. It works!! You are the man
Regarding using a table/day, here is my situation. May be you can help me find a better solution.
I am using BULK INSERT to import csv files into the db. Everyday 1 csv file needs to be imported. The number of records are around 0.5M each day without any date/time stamp. I only need the date for these 0.5M records so that i can perform queries on it later on. I need to keep previous 30 days data stored in the db.
One solution could be to insert datetime while doing the bulk insert with each record. Is it possible and efficient?
Any other solutions?
P.S i couldnt find how to comment on the answer you provided so i had to improve it