Here is the Stored Procedure code for importing comma seperated CSV files to table.
CREATE PROCEDURE [dbo].[sp_ImportScript]
@filepath varchar(2000)
AS
BEGIN TRY
declare @tmpsql varchar(3000)
set @tmpsql='BULK INSERT table'
set @tmpsql=@tmpsql + ' FROM ''' + @filepath + ''''
set @tmpsql=@tmpsql + ' WITH (FIRSTROW=2,FIELDTERMINATOR ='
set @tmpsql=@tmpsql + ''','''
set @tmpsql=@tmpsql + ',ROWTERMINATOR ='
set @tmpsql=@tmpsql + ''','''
set @tmpsql=@tmpsql + ')'
EXEC(@tmpsql)
select @@rowcount
END TRY
BEGIN CATCH
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
Thursday, March 1, 2007
0 comments:
Post a Comment
Your feedback is very important to me. Please provide your feedback via putting comments.