SSIS : Is it possible to provide input in SQL query from excel - ssis

I have to extract data using a sql query by passing values in where clause.
The values to be passed reside in excel. I don't want to hard code those values in query.
Can anyone guide me on how to pass those values.
Eg: Select Name,Age,Address from XYZ where ID in ()
Now i have to pass the ID's that i have in my excel sheet.

Assuming the excel file is in a location that's always known you can use the Excel Data Source to get to the information. Take a look at:
http://msdn.microsoft.com/en-us/library/ms141683.aspx
It does support SQL like syntax but it will be much easier if the worksheet has two rows - a column header and a data row. You pull the named parameters out of the data row.
Also, my recollection is that you do need to have Microsoft Office installed on the machine executing the SSIS job so keep that in mind as you deploy.
Once you have the values from the Excel Data Source, store them in variables where you can pass them as value parameters to your SQL query. See:
how to store sql query result in a variable and messegeBox

Using script task access the excel sheet and populate an SSIS variable(of type object). Then, build an SQL query in a FOR EACH LOOP CONTAINER by iterating over all the values. Store that SQL in another variable(string) and finally execute it using EXECUTE SQL TASK.

You can use a Script Task to iterate all values in the Excel Worksheet and append values in SSIS user variables with each values separated by a comma.
Then you can use Execute SQL Task to execute the SQL with a parameter created in Script Task

Related

Extract result set from a execute sql task and store it in a excel file?

I have a execute SQL task, that needs two input variables and a output variable to run. The SP returns a table that i'm storing in ResultSet parameter. I want to store the values in this ResultSet parameter in a excel file.
From my internet research(similar SO question, Export data from SQL Server to Excel), i found a few articles where they create a ADO.NET sources. Run a simple select query inside it and use excel destination. In my case, the parameters to SP have to be passed as variable.Hence, i can't use the harcoded SQL queries.
Can anyone please point me in the current direction? My knowledge of SSIS is very limited to be doing a good google search.
If the question is, how to store values from ResultSet parameter to Excel, you have to create a custom data source:
https://www.timmitchell.net/post/2015/04/20/using-the-ssis-object-variable-as-a-data-flow-source/

How to get data from excel and pass excel values as parameters in SQL query on pentaho etl jobs

I'm new to the pentaho etl jobs .. I need to get data from excel and pass the excel sheet value to MySQL query as parameter. If it's possible in etl pentaho jobs .. any know please help me
You create a transformation and use 'Microsoft Excel' as your input, make whatever transformation you need to do and add 'Table output' as you destination where you define your database connection. That's all.
as per understanding of your problem your parameters are defined in excel file and you want to use it in sql step.
You create a transformation and use 'Microsoft Excel' as your input, use 'set variable' and then use them as part of sql query parameters dynamically

SSIS PACKAGE, Only want Derived Columns

I have a SSIS Package that I have a For Each Loop which imports multiple txt files into a SQL Server table. That runs fine.
What I am trying to accomplish is to store the distinct filename and date it was imported into a separate table. I created a separate For Each Loop for this and then archive the txt file after it's complete with a File System Task.
The issue I am having is I put an event handler to invoke a SQL Task and Send Email task if there is a warning (I was hoping for a warning only if there were no files in the directory where the package is importing from).
However, I found a warning that a column in the Data Flow task was not being used and should be removed if not needed. But the Data Flow task requires at least one field for me to put a Derived Column task
Derived Column Field1: pulls the #User: CurrentFile from the ForEachLoop Container.
Field2 pulls the current date.
Is there a way to perform this without the warning?
It sounds like you're over-complicating thing.
You have a ForEach loop and you're therefore assigning a value into some Variable to contain the file name, #User::CurrentFile. You can get the date it was loaded through either a call to GETDATE() or reference the system scoped variable, StartTime #[System::StarTime]
The most straight forward option would be to add an Execute SQL Task wired up to the OnSuccess Precedent Constraint from your Data Flow Task. The Execute SQL Task will then have a statement like INSERT INTO dbo.MyLog(FileName, InsertDate) SELECT ?, ?, assuming OLE DB Connection Manger, and then you map in your two variables.
Easy, clean, no warnings fired about unused columns in your data flow.
What I think you have is something like this, based on
I created a separate For Each Loop for this

add parameter value to table at import SSIS

I am importing an Excel table from an ftp site to SQL using SSIS. The destination table is going to be used to calculate good and bad records based on another SQL database. Here is my problem. The Excel file is name RTW_032613_ABC_123.xls. This file name is a concatenation of a number of fields. I cannot recreate it based on the fields in the table, so I need to retain it and pass it to the new table in SQL. I have a parameter #FileName that I am using to loop through the files in the ftp folder. What I would like to do is either combine the import of data from the Excel file with the file name or insert the file name in each record after the import. I am calling the SSIS procedure from another stored procedure in SQL. I tried adding a SQL data flow task but I am not seeing where I add the insert statement on either the SQL Server Compact Destination or SQL Server Destination.
I am over my head with SSIS on this one. The key is that the parameter that I need is available in SSIS but I really need to get it passed on to my SQL table.
TIA
If I'm reading your question right, you have an SSIS package with a variable containing the filename and you want to save the filename with each row that you are sending to your SQL table? If so:
Add a derived column to the data flow, making a new column and referencing the variable in the expression
Include that new column in the mapping for the destination of your data flow, sending the filename to whichever column you would like to save that data in.
No need for a seperate SQL task.

Excel SSIS and SQL server

I want to develop an automation in SSIS.
Problem statement :
I have an excel sheet which has a single column.
Based on the values in that column (will be included as a search parameter in the SQL query) I need to fetch 2 or more columns from SQL server database
The results are to be stored in the same Excel sheet against the data obtained for that particular column.
I already have an excel macro for the same. But, now I want to develop a package for the same.
Please guide me through the necessary steps.
I will also keep trying to obtain the solution
Create an Excel Source and link it to your file
use a lookup component to perform a SQL select to obtain the missing data
Create an Excel destination to save your target data