How to send record(which is a weblink) from a table to the value of the variable in SSIS package and send that weblink through an email? - sql

I have table called Table1 with columns, col1 and col2 with col1 having weblinks for the report and col2 the name of the report. Now, i have a package with a variables var1 and var2 which should get the col1 and col2 values respectively from table1 and send it through an email. if the weblink gets updated in the table, package should send the updated link. i know the reverse way of it but trying to do somethig like this.
Appreciate any help from you guys.
Thanks

There are a few ways you can do this. You can try one of the following based on whether you are processing one row or many rows.
One-Row Solution
If you are running the SSIS package so that it will process one and only one row from the table, you can use the Execute SQL Task to get the values from your table. Begin by adding your two variables
In the task, specify the connection to your SQL Server and enter a SQL statement like this.
SELECT col1, col2
FROM Table1
WHERE <your condition to retrieve one row>
Also, on the General tab, set the ResultSet value to Single row.
On the Result Set tab, add two elements. The first row should be Result Name of 0, Variable Name of Var1. The second row will be Result Name 1, Variable Name Var2.
When the task runs, the results of the SQL statement will be stored to the variables.
Multi-Row Solution
If the SSIS package must return multiple rows, then you need a different approach. First, you will need to create another variable that is an Object data type. The SQL results will be saved to this variable.
You will have an Execute SQL Task that is similar to the one above. However, your SQL statement should return all rows to be processed. The ResultSet property should be set to Full result set. On the Result Set tab, there should be one result set, with 0 as Result Name and your new object variable as the Variable Name. Close the Execute SQL Task editor.
Add a Foreach Loop Container. Edit the container and select the Collection tab. Set the Enumerator property to Foreach ADO Enumerator. Under the Enumerator configuration, set your object variable as the ADO object source variable.
On the Variable Mappings tab, add to rows. The first row will have a Variable Var1 and Index 0, and the second row will have Variable Var2 and Index 1. The Foreach Loop Container will process each for in the result set and assign the column values to your variable. You can add any tasks in the container and they will run once for each row in the result set.

Related

How the result set of the following query in sql task can be assigned to a variable in ssis

Even after the below configuration , im not able to assign a query result to a variable
In the first form you have specified the ResultSet type as single row, and in the SQL Command you have wrote a SELECT query that may returns multiple rows.
You have to change the SQL Command, and add a TOP 1 keyword
SELECT TOP 1 ... FROM ... WHERE ...
Also if it still not working, in the Result Set Yab, try replacing the columns names with relevant indexes.
MailAddressFrom >> 0
MailAddressTo >> 1
Subject >> 2
If you are looking to store all rows returned by a SELECT Query, you should select FullResultSet option and store the result inside an Object variable:
SSIS Basics: Using the Execute SQL Task to Generate Result Sets

Executing stored procedure in a loop until a condition is met using SSIS

I have a customers table whose fields have to be updated with recent changes and also an additional column in the same table which specifies if that particular row has been updated or not, I have a procedure that does this for me
CustomerID CustomerName Address Updated
1 abc xyz Yes
2 cdb tyy No
As you can see above , the second row hasn't been updated due to NO connection to the client server.Later when the connection to server is available, all I have to do is update the column value to blank and run the procedure again till the row is updated with any changes.
I have to flow this process in a loop until all rows in the table are updated.
Could someone please help me out to do this in SSIS
The following will allow your stored procedure run until all the rows have been updated. A couple important things to note, if it's possible that there will be one or more iterations where no rows in the table will have been updated, a condition, such as a T-SQL IF statement, will need to be added to the second Execute SQL Task to check for this and assign a value to the variable accordingly. Also, the parameter syntax (using ? for the parameter place holder) is for an OLE DB connection.
Add a For Loop container, in the EvalExpression field, select an int variable and set the condition as the variable not equal to 0, i.e. #[User::Count] != 0
Within the For Loop container, add an Execute SQL Task that executes the stored procedure
Add another Execute SQL Task linked to the first one and still inside the For Loop, that has a query which returns the count of rows from the table without the updated value that will be mapped to the variable from the For Loop, such as
select ? = count(*) from dbo.YourTable where Updated != 'Yes'
On the second Execute SQL Task, go to the Parameter Mapping pane, pick your variable in the Variable Name field, set the Direction to Output, Data Type to Long, and Parameter Name to 0. The Parameter size can remain at the default of -1.

Transferring several similar named tables in SSIS

I want to create an interface between 2 databases on SQL Server 2008+ to copy several similar named tables into one.
I have n tables that all have the same naming convention, for example:
SalesInvoicePlanning2014ver1
SalesInvoicePlanning2015ver1
SalesInvoicePlanning2015ver2
etc.
The numbers can vary and do not have a set start (or end), but are always of the "int"-Datatype.
I also have a table "tabledir" that contains all table names as list. (one field) There are a total of 30-40 entries in that list with (for me) undesired entries. In the above example I would need 3 of the 30 tables.
The plan is to use a loop container to
select Top 1([name]) from [tabledir] where name like 'SalesinvoicePlanning%'
and then use the result as variable in the following SSIS Data transfer task:
Select * from [variable]
However, I'm stuck with the SQL statement to give me the desired tablename on each iteration.
Performance is not really an issue. Any advice? Am I wrong trying to use a loop-container?
You can follow below steps -
Step 1 - You can first create SQL task to get all table names into one variable lets say, TableNames of type Object(recordset) using you query.
e.g. select ([name]) as TableName from [tabledir] where name like 'SalesinvoicePlanning%'
Step 2 - Add foreach loop container to iterate over this variable TableNames to take single table name into new variable current_table and add data flow into the container to import data to destination table. Your source query will be expression like -
Select column_names from current_table

How to set multiple SSIS variables in SQL Task

Say I want to get the key values of two tables and assign to two package variables.
I can easily assign one, setting the Execute SQL Task to return a single row. But is it possible to set multiple variables with multiple result sets?
I have this SQL:
SELECT COALESCE(MAX(LogKey),0) AS LogKey FROM Log
SELECT COALESCE(MAX(HeaderKey),0) AS HKey FROM Header
I've tried setting the ResultSet property to both single row and Full result set, but neither seem to work. Do I have to use a separate Execute SQL task?
You could try this to force the values on the same resultset:
SELECT
A = (SELECT COALESCE(MAX(LogKey),0) AS LogKey FROM Log),
B = (SELECT COALESCE(MAX(HeaderKey),0) AS HrKey FROM Header)

SSIS String variable size

I would like to know what is the size limit on the SSIS string variable. I have a OLE DB data source that queries a column (alpha-numeric 10 digit) values and feeds the result set into a script task, the script task then creates a set based delete sql statement(i.e. DELETE FROM Table Where ID IN("all id's go here") and assigns the sql statement to a string variable, a third task (execute sql) then executes the sql from the variable. I am wondering if I get 10,000 values in the IN clause would that cause any issues with the string variable? Please advise
There is no limit on a string variable size .SSIS data types are derived from .net sub system so incase if you do have a very very large string value then you may run out of memory
One possible solution can be to put the ID in a temporary table in your destination database and then you can do a DELETE statement with a join between the temporary table and the table you are deleting from.
Or, you can rewrite your statement: DELETE FROM Table WHERE ID IN (SELECT ID FROM TempTable)