Hi,
I want to know y does the following script run in SQL and not in T-SQL
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) )'
EXEC(@sql)
go
it gives you the error
Msg 170, Sev 15: Line 1: Incorrect syntax near '20090714Table'. [SQLSTATE 42000]
Software/Hardware used:
ASKED:
July 14, 2009 12:33 PM
UPDATED:
July 15, 2009 5:01 PM
I tested your code, and it works for me (SQL Server 2008).
There’s a Discussion section further down the page.
The normal technique to use, would be to load the data into a staging table which is the same format as the text file. Then move it into the production table which has all the extra columns like primary keys, date fields, etc. That or use SSIS to import the file, adding in the extra columns as it processes.
I prefer the staging table technique.