?
Solved

passing a value from one 'SQL Exec task' to another...

Posted on 2014-08-21
5
Medium Priority
?
326 Views
Last Modified: 2014-08-21
is it possible to generate a value and store it in a variable in the first "sql exec task" in SSIS and then use that same value in the second "SQL Exec task"? first "SQL Exec task" connection string is different than the second one.
0
Comment
Question by:25112
  • 3
5 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40276776
Define "SQL Exec task".  A SQL task inside an SSIS package?  T-SQL statement?
0
 
LVL 5

Author Comment

by:25112
ID: 40276786
here is the example:
/* first "Exec sql task" */
/*Server 1 */
/*THis is doing a back across to server 2 called "POST" */
 
DECLARE @dtime datetime
DECLARE @dtime_in_Char varchar(1000)
DECLARE @backup_string varchar(1000)
SET @dtime= getdate()
SET @dtime_in_Char = REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(char(19), @dtime, 120),':',''),'/',''),'-',''),' ','')
SET @backup_string = 'BACKUP DATABASE [DMMart] TO  DISK = ''\\POST\backup\DMMart_'+@dtime_in_Char +'.bak'' WITH  COPY_ONLY, NOFORMAT, INIT,  NAME = ''DMMart-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD,  STATS = 100'
EXEC (@backup_string)

/* second "Exec sql task" */
/*Server 2 */
/* THis restores from a local file that came from the previous step */

USE MASTER
ALTER AVAILABILITY GROUP POSTAG1 REMOVE DATABASE [DMMart]
USE [DMMart]
ALTER DATABASE DMMart SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE MASTER
RESTORE DATABASE [DMMart] FROM  DISK = N'\\POST\backup\DMMart_20140821110230.bak' WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 100
ALTER AVAILABILITY GROUP POSTAG1 ADD DATABASE [DMMart]
0
 
LVL 5

Author Comment

by:25112
ID: 40276789
>>Define "SQL Exec task".  
Yes, "Execute SQL Task" under Control Flow in SSIS.
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 40277014
Yes, you can pass values/parameters from one SSIS T-SQL task to another.  It's rather convoluted and takes some getting used to, but once you do it's a very nice feature.
0
 
LVL 5

Author Comment

by:25112
ID: 40277200
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question