Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored Procedure: Import/Export Data

Author  Topic 

zhel04
Starting Member

38 Posts

Posted - 2011-03-16 : 01:28:18
Hi. Can someone help me or guide me on creating a Stored Procedure for Import/Export data?

Thanks and God Bless.

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-03-16 : 02:31:08
Hi,

sample procedure for bulk insert operation

CREATE PROCEDURE sp_Import
@TableName varchar(200),
@FilePath varchar(200)
AS
DECLARE @SQL varchar(2000)

SET @SQL = 'BULK INSERT ' + @TableName + ' FROM ''' + @FilePath+ ''' WITH (FIELDTERMINATOR = ''\t'',ROWTERMINATOR = ''\n'')'
EXEC (@SQL)

-- Execution;
EXEC sp_Import 'empx' , 'D:\Practice works\Projects\Table1.txt'

For Different Options for Importing Data into SQL Server please go through the below link
http://www.mssqltips.com/tip.asp?tip=1207



--Ranjit
Go to Top of Page

zhel04
Starting Member

38 Posts

Posted - 2011-03-16 : 02:59:33
Thanks a lot.. :) This is for import how bout for export do you have any idea?

God Bless..
quote:
Originally posted by Ranjit.ileni

Hi,

sample procedure for bulk insert operation

CREATE PROCEDURE sp_Import
@TableName varchar(200),
@FilePath varchar(200)
AS
DECLARE @SQL varchar(2000)

SET @SQL = 'BULK INSERT ' + @TableName + ' FROM ''' + @FilePath+ ''' WITH (FIELDTERMINATOR = ''\t'',ROWTERMINATOR = ''\n'')'
EXEC (@SQL)

-- Execution;
EXEC sp_Import 'empx' , 'D:\Practice works\Projects\Table1.txt'

For Different Options for Importing Data into SQL Server please go through the below link
http://www.mssqltips.com/tip.asp?tip=1207



--Ranjit

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-16 : 04:14:03
Use bcp for exporting data. Read about it in SQL Server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-03-16 : 04:19:41
for export you can use bcp statement

The bcp utility can be used
to import large numbers of new rows into SQL Server tables
or
to export data of tables into files

--Ranjit
Go to Top of Page
   

- Advertisement -