SQL Synatx error while creating table dynamically
I am getting error when I am trying to create table on runtime

Declare @FileName varchar(100)
Declare @File varchar(100)
set @FileName='brkrte_121227102828'
SET @File = SUBSTRING(@FileName,1,CHARINDEX('_',@FileName)-1)
--=select @File
Declare @table_name varchar(100)
Declare @ssql varchar(1000)
SET @table_name = 'DataStaging.dbo.Staging_'+ @File

SET @sSQL = 'CREATE TABLE ' + @table_name + ' ( ' +
' [COL001] VARCHAR (4000) NOT NULL, ' +
' [Id] Int Identity(1,1), ' +
' [LoadDate] datetime default getdate() ' +

' )' 
Exec @sSQL 

Error massage:-
Msg 203, Level 16, State 2, Line 16
The name 'CREATE TABLE DataStaging.dbo.Staging_brkrte ( [COL001] VARCHAR (4000) NOT NULL, [Id] Int Identity(1,1), [LoadDate] datetime default getdate() )' is not a valid identifier.

Please help me to resolve above er
April 20th, 2015 1:36am

Got the answer

issue with the Exec (@sSQL) 

thanks

Free Windows Admin Tool Kit Click here and download it now
April 20th, 2015 1:39am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics