SSIS execute sql task get value from a query statement - ssis

I am using SSIS 2008 and put a simple query (not proc) in an execute sql task (control flow). The query generate one column with a single value, what I am trying to do is based on this value to decide whether to do the following tasks. I tried mapping the value to a variable in the parameter mapping. I tried direction Output/Return value etc but all failed. The query takes no parameter. I know probably I can create a proc with a output parameter to be mapped to a variable but just wondering if there is other options (e.g. not creating proc, it's very simple query)?

As mentioned, you need to change the SQL Task to give a Result Set on a 'Single Row', you can then output that result set to a variable.
From here you can use the constraints within the Control Flow to execute different tasks based upon what the outcome variable will be; for example:

Related

Stored Procedure vs SQL Statement in SSIS Execute SQL Task and a Full Result Set

In the SSIS Execute SQL task, when I use a stored procedure to return data to a full result set, the resulting C# DataTable object only contains one row/column, with all values contained within one row/column. The rows are separated by commas, columns by dashes. However, when the same code executes via the SQL Statement, I get multiple rows/columns, so I can access via row[0].toString() etc.
This behavior occurs with both ADO.NET and OLEDB connections. Is this by design?
This link started me in the initial direction, but haven't found a definitive answer.
https://learn.microsoft.com/en-us/sql/integration-services/result-sets-in-the-execute-sql-task?view=sql-server-2014

Pass full result set from execute sql task to an OLEDB command task

I have read some blogs that give an idea about passing the full result set into a variable and then sending the variable to a for each loop container. I am stuck there. Basically I have two tables: 1. student_Class_timetable 2. students_exams_timetable.
I have a sql query that finds out the clashes between these two tables for. eg. say a student has to attend a class today between 10 to 12 but he also has to write an exam at the same time.
So I am doing an execute sql task and saving the full result set in a variable called studentlist. I now need to save the list of all these students in an audit log table before deleting them from student_Class_timetable.
ssis_screenshot
I don't know how to pass the Studentlist variable to a data flow task.
Could you please suggest a way to do that
If I were doing that, I would consider storing the data in a Recordset Destination with an Object Type VariableName and using a Foreach ADO Enumerator on that variable. A good example can be seen here.

How to create a new column with an SQL function in Pentaho PDI work-flow?

I have one sql function, let's say theFunction(item_id). It takes an item id and computes one value as its return. I read one table from the DB and I suppose to compute a new value to append for each row by this function given the item_id particular to taht row. Which desing block would do this form me with the following SQL (if not wrong).
select thsFunction(item_id);
I assume that the block gives me item_id of each row as a variable.
You can use another table input step, and have it accept fields from previous steps and execute for every row (both config options are at the bottom of the step's window).
Beware that this is a rather slow implementation. Each query is executed separately and as such each row requires a round trip to the database.
Alternatively, you can use the Row SQL Script. I believe it allows you to pass all SQL statements in a single trip to the database.
An SQL function is probably much more efficient to run in the database, for all rows at once, in stead of making a separate call into the database from PDI for each row to execute the function. So if performance is at all a relevant concern, I'd suggest a whole different strategy:
Write your rows to a table in the database. End your transformation here.
On the job level, first execute your transformation from above, then execute the function in an "Execute SQL script..." component, giving it an SQL command somewhat like "UPDATE my_temp_table set target_col = theFunction(item_id)".
Continue your job with the remaining steps in a new transformation, starting from that table as input.
This of course presupposes that you don't have too many other threads going on, but if your transofrmation is simple and linear -- or at least if it can be made single-linear at this particular step -- it may be possible to split it up into two parts before and after this SQL call.

Using variable to assign value to where clause of lookup transformation

I have a DataFlow Task which picks up a variable while running. This variable changes its value three times so the job has to run three times. I want to have a Lookup Transformation in the DFT that checks if the new value to be inserted already exists in the database for the value of the current variable.(I cannot create any unique key constraints in the database.)How do I make the where clause of the LookUp transformation pick up the value from the variable? I cannot use execute sql as it is restricted to Control flow tasks.
A better way than use a lookup is to use a MERGE statement : http://technet.microsoft.com/en-us/library/bb510625.aspx
If you still want to use a lookup, you have to disable the cache on your component (or set it to partial), then in the advanced tab you can check the "Modify SQL instruction", type your query and use variables using the "parameters..." button.

How to determine row count in SSIS dataset

I frequently encounter a situation in SSIS packages where I run a SQL Command to return a set of rows from an ADO connection. There are cases where I want to branch based on the number of rows returned. The ado resultset is stored in an SSIS 'object' datatype. Is there a way in SSIS expression or Script component to get that count of rows?
Instead of using the Execute Sql task, use a dataflow task like this.
Use a source component to retrieve your data
Use a rowcount component to store your rowcount into a variable
Use a recordset destination component and store that in your original variable (system.object type)
Then return to the control flow and continue as you planned, using the rowcount variable to branch your control flow.
You can create a precedence Constraint after the Execute SQL Task to the object datatype variable, #[User::objectvariable]>0 as expression in precedence constraint. However in Execute SQL Task you will get resultset to the object variable.