473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Exporting data from SQL table to Excel File - How to delete rows before inserting new

Hi,

Question pls. I have an MS SQL local package where it exports data from SQL table to Excel file. My question is, how can I erase all the records in my excel file before i export the new data from SQL table?

What i want is to delete the rows in the destination file before inserting new records.

Note:
I cannot do the drop & recreate table because the users has no permission to do this in the database. Only the DB admin is allowed to drop & create table.

Thanks a lot.
Feb 6 '07 #1
8 10061
iburyak
1,017 Expert 512MB
Hi,

Question pls. I have an MS SQL local package where it exports data from SQL table to Excel file. My question is, how can I erase all the records in my excel file before i export the new data from SQL table?

What i want is to delete the rows in the destination file before inserting new records.

Note:
I cannot do the drop & recreate table because the users has no permission to do this in the database. Only the DB admin is allowed to drop & create table.

Thanks a lot.
Create a view that limits number of exported rows and use it in DTS package instead of a table.

Good Luck.
Feb 6 '07 #2
hi iburyak,

just the same, the records are being appended to the excel file. what i want is to delete the rows in the destination file before inserting new records.

thanks.
Feb 6 '07 #3
iburyak
1,017 Expert 512MB
Did you create a view that removes unwanted records?
Execute a view on a Server side and make sure this is the data you want to export, don't create a view to select * from table_name it will not correct a problem.

You need to give me more information then just I want to delete records.
It is a wrong approach to load all records and delete on destination side you need to load only necessary records.
Feb 6 '07 #4
Hi Iburyak,

The Question is... this excel file is getting populated everyday and everyday before porting data to the excel the old data has to be erased and new data filled up.

Any help on that.

Thanks in advance..
Mar 17 '07 #5
I have succesfully executed a dts-package from SQL server 2000 to an excelfile
How can I delete a .xls destinationfile in the Job.
Nov 18 '08 #6
carpel
2
@LimaCharlie

How to delete rows in the destination file before inserting new records.

I suggest create worksheet Master with only header row and copy the worksheet Master into worksheet to fill every time.

Steps to do in a store procedure are:
1. Create a “Master.xlsx” worksheet with header columns: Name and Date
2. exec master..xp_cmdshell 'copy c:\Master.xlsx c:\test.xlsx'
3. INSERT INTO OPENROWSET(
''Microsoft.ACE.OLEDB.12.0''
, ''Excel 12.0 Xml;Database=C:\ test.xlsx;''
, ''SELECT * FROM [foglio1$]''
)
SELECT [Name], GETDATE() as Date FROM msdb.dbo.sysjobs

Happy coding by carpel
May 3 '09 #7
ck9663
2,878 Expert 2GB
My recommendation would be to create your target file dynamically. This way, you can have more flexibility.

--- CK
May 4 '09 #8
carpel
2
Hello CK,

you are right!

the full version is:

ALTER PROCEDURE [dbo].[ExportStopreProcedureInExcel]
(
@QueryString VarChar(8000) ='',
@MasterFile VarChar(100),
@CopyFile VarChar(100)
)
AS
BEGIN TRY


DECLARE @SQLSTR nvarchar(MAX)

SET @SQLSTR = 'exec master..xp_cmdshell ''copy ' + @MasterFile +' '+ @CopyFile+''''

exec( @SQLSTR)

SET @SQLSTR = '

INSERT INTO OPENROWSET(
''Microsoft.ACE.OLEDB.12.0''
, ''Excel 12.0 Xml;Database=C:\GiorniLavoroSuiFV.xlsx;''
, ''SELECT * FROM [foglio2$]''
)
'+ @QueryString


EXEC (@SQLSTR )


END TRY
BEGIN CATCH
DECLARE @ErrMsg VARCHAR(8000),
@ErrSeverity INT,
@ErrState INT;

SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY(),
@ErrState = ERROR_STATE();

RAISERROR (@ErrMsg,
@ErrSeverity,
@ErrState
);
END CATCH

'If anything can go wrong, it will' (Murphy)

See you soon ...carpel
May 5 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andres Romero | last post by:
I have a button in my html page for exporting to excel files using the RenderControl function. When the table generated is small in rows size it works fine, but when there are much more rows (more...
2
by: Mike P | last post by:
How do you go about exporting data in excel to a C# dataset? Any help would be really appreciated. Cheers, Mike
2
by: bienwell | last post by:
Hi all, Do you have any source code to import data from Excel file or text file into database in ASP.NET program ? Please give me your reference if you have. Thanks in advance
1
by: Yoavo | last post by:
Hi, I need to read data from excel file. How do I do it ? Yoav.
1
by: madhu sudhan | last post by:
HI, I want to read data from excel file and export this data to dataset. I know abt the basics of opening a file using application, workbook and worksheet classes. But i don't know how to read...
1
by: syam217 | last post by:
Please help me out in reading data from Excel file and storing it in SQL Server 2000 database. Its very urgent. Thanks in advance.
1
by: dixon | last post by:
Hi please help i'm trying to read data from excel file using VB 2005 and display it to a listbox and when name clicked on a list box details of that name should be displayed on the labels such as...
1
by: arshigill | last post by:
I want to import data from excel file inot mysql database table but unable to solve this problem. I have searched google and find an example of importing of CSV excel file. But when I modify it...
1
by: bienwell | last post by:
Hi all, I'm going to develop an ASP.net page (VB) that allows users to export data into the zip file. Do you have any sample codes? Please give me the source codes if you have. One more...
3
by: qfchen | last post by:
Hi In order to save data into excel file in my application, I need to define Dim excelApp As New Excel.Application but I got error message: "Type Excel.Application" is not defined. What component...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.