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 2005 Forums
 Transact-SQL (2005)
 Delete old rows from Excel and insert new records

Author  Topic 

mayurcreation
Starting Member

16 Posts

Posted - 2007-09-12 : 10:14:06
Hi

I need to export table into excel file each time I run store procedure.

When I run store procedure it should delete all old records from excel file and than insert new records into excel


insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Projects\PAYOUTS\FILES\MayurTestOutPut.xls;',
'SELECT bwnum, description, manager_id, salesperson_id, salesperson_name, salesperson_perc_of_account, salesperson_payout_deal FROM [Sheet1$]')
select bwnum, description, manager_id, salesperson_id, salesperson_name, salesperson_perc_of_account, salesperson_payout_deal from view_payoutsvalue


How to delete old rows from excel file ??

Please help - It is urgent for me...

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2007-09-12 : 10:16:09
Why not overwrite the excel file?

or populate an excel template?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-12 : 10:39:47
http://sqlteam.com/forums/topic.asp?TOPIC_ID=87225&whichpage=2#332121

Madhivanan

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

mayurcreation
Starting Member

16 Posts

Posted - 2007-09-12 : 10:46:30
Overwrite will not work because numbers of rows are not sure and data too...

Thanks!!

quote:
Originally posted by ValterBorges

Why not overwrite the excel file?

or populate an excel template?

Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2007-09-12 : 10:54:20
sure it will...

import the xls then delete or modify what you need to do then export and overwrite



--------------------
keeping it simple...
Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2007-09-12 : 18:49:22
Yes it will I do it all the time.

Create a template and in the first step of your dts copy the template to a new filename ex: ExcelTemplate.xls --> MyReport.xls

In the second step use a data transform to pull data from query into myreport.xls

In the third step rename MyReport.xls to MyReport4Q.xls

PS: If anyone is interested in a SQL Job in CT with excellent pay send me a resume to ValterBorges@msn.com



Go to Top of Page

mayurcreation
Starting Member

16 Posts

Posted - 2007-09-13 : 10:07:21
Thanks for your help.
Go to Top of Page
   

- Advertisement -