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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 export to new excel and existing excel

Author  Topic 

lilinikco
Starting Member

28 Posts

Posted - 2011-03-15 : 01:49:13
hi all.
how to export data from one sql query to existing and new excel?I use
INSERT INTO OPENROWSET ('Microsoft.ACE.OLEDB.12.0', 'Excel 8.0;Database=c:\contact.xls;','SELECT * FROM [Sheet1$]')SELECT * FROM authors
for export to existin excel but get error:column name or number of supplied values does not match table definition.
pleas give me T-sql for 2 purpose.thanks

lili@@

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-15 : 02:29:20
For both purposes you can use the same code, however much as i remember,

1) you will need to name the columns in Excel file.
2) use the column names instead of * and ensure that number of columns are equal to the Supplied values e.g.

Columns Names= SELECT Col1,Col2,...,ColN FROM [Sheet1$]'
Number of Supplied Values = Select Col1,Col2,...,ColN from Authors;


Cheers
MIK
Go to Top of Page
   

- Advertisement -