larsbloch
10/5/2017 - 5:55 PM

Finding environment dynamically for a stored procedure

Finding environment dynamically for a stored procedure

Declare @reference_id_select int
Declare @environment_variable nvarchar(20)
SET @environment_variable = (SELECT Environment = CASE(LOWER(@@SERVERNAME))
WHEN 'sv0091\test' THEN 'QA'
WHEN 'sv0091' THEN 'PROD'
WHEN 'sv0143' THEN 'Dev and Test'
END)
set @reference_id_select = (SELECT
--pck.name, p.name, f.name,
r.reference_id
FROM [SSISDB].[catalog].[packages] pck
INNER JOIN [SSISDB].[catalog].[projects] p
ON pck.project_id = p.project_id
INNER JOIN [SSISDB].[catalog].[folders] f
ON p.folder_id = f.folder_id
INNER JOIN [SSISDB].[catalog].[environment_references] r
ON p.project_id = r. project_id
WHERE
pck.[name] = 'SendMailTilMistænkte.dtsx' AND LOWER(r.environment_name) = LOWER(@environment_Variable))