There are several technique to import file in SQL Server from external source like SSIS, BULK INSERT command, Import/Export wizard, OPENROWSET etc. one of them xp_cmdshell is use to import text file to SQL Server.
Below script can be use to import text file to SQL Server.
Note: Before using below script we have to enable xp_cmdshell once.
CREATETABLE#TEMP ( Result VARCHAR(MAX) ) DECLARE@pathVARCHAR(8000) DECLARE@QueryINT -- read from text file SET@path='TYPE D:\Test.txt' INSERTINTO#TEMP EXEC@Query=master.dbo.xp_cmdshell@path SELECT * FROM #TEMP GO DROPTABLE#TEMP |