I have five different text files in my Local Drive(D). Lets try to Insert this all data from text file to below created structure table in SQL Server.
Creating a Store Procedure to insert all data from different text file to a SQL table
Now execute the SP
Exec [Foo_Insert]
Creating table structure
create table Foo ( ID varchar(10), Name varchar(30), Mobile varchar(10) )
Create procedure [dbo].[Foo_Insert] as declare @file varchar(30) declare @c int=1 declare @n int =5 begin while (@c<=@n) begin EXEC (' BULK INSERT Foo FROM ''D:\SSIS_Work\Foo'+@c+'.txt'' WITH ( FIELDTERMINATOR = ''\t'', ROWTERMINATOR = ''\n'')' ) set @c=@c+1 end end
Exec [Foo_Insert]
No comments:
Post a Comment