How to fetch a date parameter from the SQL Task and pass it on to Data Flow tasks - ssis-2012

I need to fetch a parameter from "Execute SQL Task" and pass it on to 10 different Data Flow tasks,
so that all these 10 DF uses the same parameter which is been generated by Execute SQL task flow.
So far what i have done is this;
I have the SQL Task editor and used the connections type as ODBC, SQLSourceType=Direct Input & SQL Statement = select max(date) from table where package = 'PackageName';
This SQL Task gets connected to 10 different Data Flows.

I think what you are trying to do is execute the sql script and return the value (the date) into a variable. Then have that variable available to the data flow tasks so they all have the same value.
Assuming this is the case, you need to first declare a variable in the package to hold the date returned from the query. Make sure the scope is available to the entire package.
Next, in order to setup your sql task correctly, you need to map the results of the sql script to the variable. In the SQL Task Editor, in the General Tab, set the result set to Single Row. Next, add a variable under the Result Set tab to receive the date from the query. For Result name, that will be the column returned from the query that is executed (you should give a name to column that returns max date). The variable name is where you put the variable you declared in the package. Now, when you execute the package the value from the query is stored in variable and is available to be used wherever you want.
I can't comment that much about how to apply that variable in the dataflow tasks without knowing which type of tasks you will use it in. But from this point, you can use the variable just like any other static variable that you would create.
Hope that helps.

Related

Creating an execute SQL task at runtime

I am working on a SSIS package which checks the performance of stored procedures using extended events. We have an execute SQL task having a SQL query which is determined at run time as the arguments for those (Read) stored procedures are already hard coded and stored in a table.
Now, I need to run (write) stored procedures calls as well for which I can not hard code the arguments as they are (dynamically generated) dependent on output set of the previous stored procedures. Arguments and result set are not identical for each stored procedure and so the difficulty to use a single execute SQL task.
I thought of creating separate execute SQL task for each (write) stored procedure and add them to sequence container but that doesn't seem like a practical approach.
Can somebody suggest any approach to this problem?

Input from variable and excel to oledb destination in ssis 2012

I have a situation where I need to get data from excel sheet and sql table then store it into a single sql server table.
Below steps I have completed already,
1.In control flow, by using execute sql task, fetched data from sql and assigned it to variable.
2.Then added Data flow task in control flow.
3.In data flow added Excel source and oledb destination.
When I trying to edit oledb destination I can only able to see excel sheet columns,
How to I do get variables also in Oledb destination? or is there any other best approach ?
You will need to add a merge join control inside of a data flow task.
Probably easier to change your execute sql task to be a second data source within your data flow task and then join on the key within a merge join control.
Be warned the merge join requires the data to be sorted. If the data is sorted on input, you can tell SSIS that by setting the input / output properties of the advanced editor. Otherwise, you can add a sort task after each data source.

How to Store an Aggregated Value in a Stored Procedure?

I am using SQL Server 2012 and trying to write a stored procedure that will have two components:
1. Select statement that will return several rows
2. Another component will have an aggregated value based on some conditions.
So, for the second component, I am thinking to declare a variable in the stored procedure and store the aggregated data there.
Now, my question is can I populate my output parameter with the data stored in previously declared variable and access the parameter from SSRS 2012?
I would appreciate any suggestion(s) to get me started.
Thank you

What order are result sets returned when using JDBC callable stmt to stored proc?

(1) When you open multiple cursors in a stored procedure, and then use a JDBC callable statement to iterate through the result sets, each in turn, are the order in which they are returned the same order in which they cursors are opened in the stored procedure? Or reverse of that? Or....?
(2) Is there a way to specify by sequence number or name which result set to process first?
For 1: The order of returned resultsets is undefined for JDBC, so it will depend on your actual database system. That said, it would be highly illogical for a stored procedure to return results in a different order than the order they are produced by the stored procedure.
For 2: Once again, this is not defined by JDBC. However I haven't heard of database systems that would allow you to control the order of returned results by any means other than their order in the stored procedure.

TADOQuery filter and an expression always true

I am trying to filter some records from a TADOQuery. I set the filtered property to true and when I set the filter to field='value', all works fine. I would like to dynamically build this filter by appending
<space>AND field='value'
to a value always true, and I thought 1=1 would do the trick. So I would have 1=1 as the default filter and then just append AND field='value' to it as necessary.
This, however, does not work. The error message reads:
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
Could anyone please tell me what could I use as a versatile always-true expression for this filter?
I suppose it goes without saying, but it depends on the OLE DB provider whether or not this works. When you set a filter on an existing record set, it ends up going through a different OLE DB interface (IViewFilter if I remember correctly). So even if a filter works in a WHERE clause on an SQL statement, it does not necessarily mean that it will work as a filter. The filter that you set ends up getting parsed apart into the component pieces and then passed to the OLE DB interface. It may be that the provider's implementation is not expecting a filter of the form "constant = constant". As a workaround, you might try setting it all in the WHERE clause of the SQL statement.
You have to set the 'Filtered' property to False if you are not filtering something, and set it True and your condition when you want the resultset to be filtered.
I would dynamically build the correct SQL property though so that you always exactly know what is being send to the database (and you are sure that only those records you want is received by your program).
The 1=1 trick works fine in the where clause of a query, but not in the filtered property. If you want to disable the filter, set filtered to false and all records will be returned.
The problem with filtering is that it is done client side. If you are using a database engine such as SQL Server and expect to have a large set of records to filter, then your better served by changing the SQL Query which will allow the database server to return only the records requested. Just remember to close your TAdoQuery first, change the SQL then re-open.
A trick I use to avoid returning the entire dataset (used for large datasets) is to consider a maximum number of records I want to display, then use the TOP SQL Syntax to return one more than the number of records I wanted to display 'n' ...if I reach that number, then I notify the user that there were more than n-1 records returned and to adjust the search/filter criteria.

Resources