How do I delete excel rows in SSIS? - sql-server

Is it possible to delete rows in an excel worksheet from SSIS?

From forum
create a file system task in control flow, deleting the file.
create a sql task, excel connection type, i used my previous excel connection for this, then used a create table script as my sql statement
left my previous export object the same, then linked the flow of these in this order described.

An arctile by microsoft claims that you cannot delete an entire row however you can delete a value in a cell. http://support.microsoft.com/kb/257819
This thread relates to someone with the same problem:
http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.adonet/2006-12/msg00245.html
In short, it seems like the answer is 'no', you cannot delete an entire row using ado.net via SSIS. You may be able to use excel automation or vb.net in excel itself to accomplish this task.

I also did it by following the steps suggested by Gulzar but, in case anyone wants the details, this is what I did:
I originally had a task to read some information from SQL Server and export it to Excel:
I then added the suggested tasks, one to delete the destination Excel file and one to recreate it:
This is the task to delete the file, it's a "File System Task":
This is the task to re-create the Excel file, it's an "Execute SQL Task":
The following needs to be set for this "Execute SQL Task":
a. Connection Type is "Excel"
b. As suggested, the connection is the same one used by the original Export task
c. The SQL statement was copied from the original Export task
That's basically it. Run it and it should work. My connection to SQL Server looks like this:
My Excel connection, which was originally created when the Export task was created, looks like this:
In the "Data Flow" section, using the Source Assistant, the original "OLE DB Source" has this:
And, using the Destination Assistant, the original Excel Destination has this:
This is the SQL Statement that I copied from the original Excel Destination:

Related

SSIS: import data from excel to sql server database with file last modified date condition

My goal is to build automatic process, which imports data from multiple xlsx files from certain directory to sql server database in regular phases.
I already created SSIS package, which imports data to sql server database. But everytime if I run this package, all xlsx files data will be inserted, but I would not like to import all data again, I would like to import just those xlsx files again, which have been updated after last import.
Currently my data flow is following:
Excel source > OLE DB Destination which runs inside foreach loop container.
I imagine something like that:
I have to insert last import timestamp with file name into some log table and then have to compare it with the xlsx last modified date. But I do not know how to do it. Hope that someone could provide some step by step instructions.
This link will give you step by step answer.
You need to take care about flat file connection to excel file connection and join based on last modified date column.

SSIS Excel Destination is Empty

I'm having an issue exporting a large dataset (500k+) to Excel via SSIS, where the output file ends up with 0 rows exported. Before saying that I shouldn't be exporting that many records to Excel, let me state that I know and normally wouldn't. Accounting does not want a CSV and is unwilling to open a CSV in Excel.
Using Visual Studio 2012 SSDT, here are the components involved.
Execute SQL Task -> Creates the empty file with headers
Data Flow Task ->
OLE DB Source -> SQL Query
Excel Destination
While the package is running, you can see records flowing from the source to the destination. The package completes without error, but when you open the file, it's empty. The only thing in there is the header.
If I select the Top 1000 records and export to Excel, it works as intended.
Some things I've tried:
Export to Excel on the network
Export to Excel locally
Export to CSV to Excel on both network and locally
Export to Ole DB Destination using Office Access Database Engine 12.0 with "Excel 12.0" extended properties.
Tried running as different users
All with the same outcome.
Can anyone provide any insight into why this may be happening and how to proceed?
We experienced a similar behaviour, when runnig the ETL in a SQL Server Agent job. Debugging it in Visual Studio, worked, however. So I do not know, whether this solution applies to you.
The reason was that the user, under which the package ran, did not have access to C:\users\Default.
I found this out by using sysinternals process monitor.
I was inspired by that post: Empty Excel File permissions issue: SSIS Excel Destination buffers large record sets through C:\Users\Default
[I explained my search for the bug in my blog: https://www.csopro.de/biblog/2018/04/ssis-fehlerbehebung-bei-excel-destination-schreibt-keine-zeilen/ Unfortunately it is in German]

Copying data from one database to another using SSIS

I am writing a SSIS package and trying to extract the data from one database to another. I have created a Execute SQL task and using the following statement INSERT INTO dbo.getParties EXEC dbo.getParties to perform the operation. This works when the source and destination our in the same database. How do I handle this when the source and destination are in different databases. You can associate only one connection manager to a task.
Do I connect to the source and in the SP call the destination. Is it the right way of doing it
Below is the design of my template
Use Data Flow component where you can set up the source and destination connection strings.
..and inside the data flow task use the Destination and Source Assistants that let you define its own connection string for each.
Of course, besides these you can also apply any sort of data transformations you wish.
Edit:
Since you your source is SQL Command (stored procedure) you need to define it in your source assistant. As you can see here, just change Data Access Mode to SQL Command and set to EXEC getParties:
In the Execute SQL Task INSERT INTO Command just add the Database name to the Table name. ex:
INSERT INTO Db1.dbo.Table1
SELECT * FROM Db2.dbo.Table2
Side Note: i think that it is better to use DataFlow Tasks to copy data, because it is faster and provides more controls and error handling

Create a Job for exporting a SQL Server view into Excel on a daily basis

I am using SQL Server; is there a way to create a scheduled Job which is going to take a view and export it into an Excel file every day?
With the addition of: creating a new folder named by the timestamp, and the file name will have the timestamp as part of its name as well, something like
C:/excel/221120170830/name221120170830.exl
I tried looking around but so far I couldn't find any way to do it.
Maybe I am missing something?
Yes, basically you need to combine 3 technologies:
SQL Server Agent Jobs
Powershell
Export Data Wizard/SSIS package
The idea is to create a job with as a first step, a Powershell script that checks if a folder exists and if not, creates it. The next step executes the SSIS package you have created, following the guidelines in the above link.
The tricky part may be uniquely naming your Excel file, but you first export the file to a temporary location and then, using another Powershell step, rename it and store it in the correct folder.

How to execute folder with SQL Server 2008 scripts

I have a folder with a .sql files; 1 file per query. I want to execute all queries/ sql files and save them as csv.
Is there a way to do that automated without using the windows cli (disabled in my environment). I do have the SQL Server Management Studio.
I would approach this task using SSIS, providing you have Business Intelligence Development Studio (BIDS) installed.
First create a 'Foreach Loop Container' pointed to the folder with the SQL files, then use a variable to retreive each file name.
Next, create a flat file connection and set the 'Connection String' property to the variable that contains the file location.
Next, using the 'Execute SQL Task' component set the 'SQLSourceType' to 'File Connection' and the 'FileConnection' to the one created in the previous step.
Finally, depending on how the data is returned you have a couple of options, if the result set is small, only a row or a single column, then you can save the results to a variable and using a 'Dataflow' task create a 'Derived Column' component and export the contents of that variable to a CSV file. Or, if the dataset is larger you could dump the results to a temp table and then using an 'OLE DB Source' and 'OLE DB Destination' you could push the full result set straight into a CSV.
Hopefully this isn't too convoluted of a solution, this approach has the advantage of being able be run from either a remote machine or from the server itself, plus you can automate its execution with a SQL Agent Job.
Create a VB.NET console application.
Generate a list of files that end in .SQL from the folder in question.
Load the contents of each file into individual SQL Commands
Execute the SQL Command for each, storing the results in DataSets.
For each table in each dataset, create a new .csv file
For each .csv file, you will need to iterate over each cell in the datatable, and utilize proper escaping for .csv files.
Use 'for' in combination with either sqlcmd or bcp command for each file in the script folder.

Resources