Direct Data Load from external file to SQL Server Table and Vice Versa
## Using OpenRowSet we can load data from an xl file to a table
## Using BCP (bulk copy) we can write the output of a XPATH query to an xml file.
ref:
http://www.mssqltips.com/sqlservertip/1633/simple-way-to-export-sql-server-data-to-text-files/
http://thiagsundar.wordpress.com/export-data-to-text-file/
http://www.simple-talk.com/sql/t-sql-programming/beginning-sql-server-2005-xml-programming/
insert into dbo.Customers_xl
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;IMEX=1;HDR=NO;DATABASE=E:\sample_entry.xls', 'Select * from [Sheet1$]');
## Using BCP (bulk copy) we can write the output of a XPATH query to an xml file.
declare @sql varchar(8000)before doing this The first thing you have to do is make sure xp_cmdshell is enabled
SELECT @sql = 'bcp "SELECT TOP 5 * FROM AdventureWorks.HumanResources.Department for xml auto,elements" queryout c:\myXML.xml -c -t -T -S "MININT-CM4Q9R0\SQLSERVERDEV2008"'
exec master..xp_cmdshell @sql
EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE
ref:
http://www.mssqltips.com/sqlservertip/1633/simple-way-to-export-sql-server-data-to-text-files/
http://thiagsundar.wordpress.com/export-data-to-text-file/
http://www.simple-talk.com/sql/t-sql-programming/beginning-sql-server-2005-xml-programming/
Comments
Post a Comment