Sample Header Ad - 728x90

Identifier that starts with is too long. Max length is 128

-1 votes
1 answer
12551 views
I referenced a few other blogs and I can't isolate the issue to this logic. Code is below. Throws the error message attached. -- 1. Import Multiple Delimited Text Files into a SQL Database -- 1.1 Define the path to the input and define the terminators USE [Openair_Integration] DECLARE @Path NVARCHAR(255) = 'C:\\Users\nicolas.gutierrez.su\Downloads\\' DECLARE @RowTerminator NVARCHAR(5) = CHAR(13) + CHAR(10) DECLARE @ColumnTerminator NVARCHAR(5) = CHAR(9) -- 1.2 Define the list of input and output in a temporary table IF OBJECT_ID('[dbo].[Files_Temporary]', 'U') IS NOT NULL DROP TABLE [dbo].[Files_Temporary]; CREATE TABLE [dbo].[Files_Temporary] ( [ID] INT , [FileName] NVARCHAR(255) , [TableName] NVARCHAR(255) ); INSERT INTO [dbo].[Files_Temporary] SELECT 1, 'booking.csv', 'dbo.booking' -- 1.3 Loop over the list of input and output and import each file to the correct table DECLARE @Counter INT = 1 WHILE @Counter 0 BEGIN SET @CreateHeader = @CreateHeader + '[' + LTRIM(RTRIM(SUBSTRING(@Header, 1, CHARINDEX(@ColumnTerminator, @Header) - 1))) + '] NVARCHAR(255), ' SET @Header = SUBSTRING(@Header, CHARINDEX(@ColumnTerminator, @Header) + 1, LEN(@Header)) END SET @CreateHeader = @CreateHeader + '[' + @Header + '] NVARCHAR(255)' SET @SQL_CreateHeader = 'CREATE TABLE [' + @TableName + '] (' + @CreateHeader + ')' EXEC(@SQL_CreateHeader) END ------------------------------------------------------------------------------------------------------------------------------------------------------------- PRINT 'Inserting data from ''' + @FileName + ''' to ''' + @TableName + '''.' DECLARE @SQL NVARCHAR(MAX) SET @SQL = ' BULK INSERT [dbo].[' + @TableName + '] FROM ''' + @Path + @FileName + ''' WITH ( FIRSTROW = 2, MAXERRORS = 0, FIELDTERMINATOR = ''' + @ColumnTerminator + ''', ROWTERMINATOR = ''' + @RowTerminator + ''' )' EXEC(@SQL) SET @Counter = @Counter + 1 END; -- 1.4 Cleanup temporary tables IF OBJECT_ID('[dbo].[Files_Temporary]', 'U') IS NOT NULL DROP TABLE [dbo].[Files_Temporary]; IF OBJECT_ID('[dbo].[Header_Temporary]', 'U') IS NOT NULL DROP TABLE [dbo].[Header_Temporary]; identified to long
Asked by NicolasGutierrezToD (13 rep)
Aug 14, 2019, 07:05 PM
Last activity: Aug 17, 2019, 07:44 PM