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

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.
LVL 5
25112Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Define "SQL Exec task".  A SQL task inside an SSIS package?  T-SQL statement?
0
25112Author Commented:
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
25112Author Commented:
>>Define "SQL Exec task".  
Yes, "Execute SQL Task" under Control Flow in SSIS.
0
Scott PletcherSenior DBACommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
25112Author Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.