Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

Import data from excel file into DB - SQL

declare @SQL nvarchar(max) = '

CREATE TABLE #TempTable
( [Field1] nvarchar(max) NULL,
    [Field2] nvarchar(max) NULL,
    [Field3] nvarchar(max) NULL ); 


BULK INSERT #TempTable  FROM ''<FullPath>FileName.csv'' WITH --if the path is in the network - need to write the Full-path of the drive
(
KEEPIDENTITY,
FIELDTERMINATOR = '','',
MAXERRORS = 10000,
KEEPNULLS, 
ROWTERMINATOR=''
'',
FIRSTROW = 2,
CODEPAGE = ''1255''
);

select * from #TempTable
Insert into TableNameInDB(Field1,Field2,Field3)
select * from #TempTable
'

EXEC sp_executesql @SQL
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Import #data #excel #file #DB #SQL
ADD COMMENT
Topic
Name
5+1 =