Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSIS - Assign value to a variable - Need ServerName from DestinationConnectionOLEDB as @Enviro from email Expand / Collapse
Author
Message
Posted Thursday, June 7, 2012 8:16 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, October 16, 2012 1:25 PM
Points: 31, Visits: 30
I have an SSIS package that has multiple email task that informs of success or failure of package tasks... I have expressions in the email "subject" that I need to get two more parts in it... 1st is the server name the connection is using; when the dtsx package is executed instead of having three packages for test, training production; the connection is changed at runtime; I want to use my user variable or if there's a system that I can't find but whatever I need the connection "ServerName" to be sent in the email...

"Package>>> " + @[System::PackageName] +" was executed at>>> " + (DT_WSTR, 40) @[System::StartTime] + " by user>>> " + @[System::UserName] + " on Machine>>> " + @[System::MachineName] + " Server>>>" + @[User::Enviro]


@[User::Enviro] How to get the value to be the server name from the connection manger?


2nd would be good to know for me to use... if I add another User:TotalRecordsAdded how to set the value from the insert task to the user variable??


Thank you,

Barry

Post #1312538
Posted Thursday, June 7, 2012 8:48 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
There may be a better way to get the server name, but the way I do it is run an SQL task and query @@SERVERNAME, then store that into a package-level variable from the result-set.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1312566
Posted Thursday, June 7, 2012 9:01 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 5,233, Visits: 9,476
Barry

How do you configure the server name for the connection string? Do you use a dtsConfig file, or a SQL table, or is it hard coded? Does the server name change during package execution (in other words, does the package loop through several servers)? Gus's way will certainly work, but if there's a way to use an existing variable then I think that would be better than incurring a connection to the database.

For your second question, I'd use the OUTPUT clause in your INSERT statement to populate a table variable, the do a SELECT COUNT(*) FROM that variable - that's assuming you're not writing millions of rows at a time into the table?

John
Post #1312576
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse