dbTalk Databases Forums  

Passing Global Variable into Execute SQL Task

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Passing Global Variable into Execute SQL Task in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Scott Lindsey
 
Posts: n/a

Default Passing Global Variable into Execute SQL Task - 02-09-2004 , 08:10 AM






I am trying to pass a global variable value into the
variable @RPT_BEGIN_DATE in an "Execute SQL" task. The
variable is part of the WHERE clause. The "Execute SQL"
task is as follows:

declare @RPT_BEGIN_DATE datetime

-- Generate report detail for failed jobs/steps

insert into T9801_EMAIL_JOBS_FAILED (EMAIL_LINE_TXT)

select substring(@@servername,1,11) +
substring(' ',len(@@servername),11) +
substring(j.name,1,43) +
substring
(' ',len
(j.name),43) +
substring(jh.step_name,1,33) +
substring(' ',len
(jh.step_name),33) +
-- Calculate fail datetime
CONVERT(CHAR(26),
dateadd(ss,cast(substring(cast(run_duration +
1000000 as char(7)),6,2) as int), -- Add Run
Duration Seconds
dateadd(mi,cast(substring(cast(run_duration +
1000000 as char(7)),4,2) as int), -- Add Run
Duration Minutes
dateadd(hh,cast(substring(cast(run_duration +
1000000 as char(7)),2,2) as int), -- Add Run
Duration Hours
dateadd(ss,cast(substring(cast(run_time + 1000000
as char(7)),6,2) as int), -- Add Start Time
Seconds
dateadd(mi,cast(substring(cast(run_time + 1000000
as char(7)),4,2) as int), -- Add Start Time
Minutes
dateadd(hh,cast(substring(cast(run_time + 1000000
as char(7)),2,2) as int), -- Add Start Time
Hours
convert(datetime,cast (run_date as char
(8))))))))),109)
from msdb..sysjobhistory jh join msdb..sysjobs j on
jh.job_id=j.job_id

where (getdate()
Quote:
-- Calculate fail datetime
dateadd(ss,cast(substring(cast(run_duration +
1000000 as char(7)),6,2) as int), -- Add Run
Duration Seconds
dateadd(mi,cast(substring(cast(run_duration +
1000000 as char(7)),4,2) as int), -- Add Run
Duration Minutes
dateadd(hh,cast(substring(cast(run_duration +
1000000 as char(7)),2,2) as int), -- Add Run
Duration Hours
dateadd(ss,cast(substring(cast(run_time + 1000000
as char(7)),6,2) as int), -- Add Start
Time Seconds
dateadd(mi,cast(substring(cast(run_time + 1000000
as char(7)),4,2) as int), -- Add Start
Time Minutes
dateadd(hh,cast(substring(cast(run_time + 1000000
as char(7)),2,2) as int), -- Add Start
Time Hours
convert(datetime,cast (run_date as char
(8))))))))))
and (@RPT_BEGIN_DATE
<
-- Calculate fail datetime
dateadd(ss,cast(substring(cast(run_duration +
1000000 as char(7)),6,2) as int), -- Add Run
Duration Seconds
dateadd(mi,cast(substring(cast(run_duration +
1000000 as char(7)),4,2) as int), -- Add Run
Duration Minutes
dateadd(hh,cast(substring(cast(run_duration +
1000000 as char(7)),2,2) as int), -- Add Run
Duration Hours
dateadd(ss,cast(substring(cast(run_time + 1000000
as char(7)),6,2) as int), -- Add Start
Time Seconds
dateadd(mi,cast(substring(cast(run_time + 1000000
as char(7)),4,2) as int), -- Add Start
Time Minutes
dateadd(hh,cast(substring(cast(run_time + 1000000
as char(7)),2,2) as int), -- Add Start
Time Hours
convert(datetime,cast (run_date as char
(8))))))))))

and jh.run_status = 0

Thanks in advance for the help!
Scott Lindsey


Reply With Quote
  #2  
Old   
Russel Loski, MCSD
 
Posts: n/a

Default RE: Passing Global Variable into Execute SQL Task - 02-09-2004 , 12:16 PM






You ready for some unnecessary hassle? I spent maybe a half a day with this problem

What you cannot do: create a sql statement with a ? as a placeholder for the parameter, then set the parameter

Here goes
0) I presume you have added the global variable ahead of time

1) add line (preferably at the top of the package
set @RPT_BEGIN_DATE = getdate(

2) Save the task

3) Open disconnected edit. Find the executesql task that you just created

4) Click on InputGlobalVariableNames. Click the Edit button

5) Add the name of your Global variable to the list (I think that it is a comma delimited list)

6) Save (Click OK

7) Click the SQLStatement lin

8) Find the line with "set @RPT_BEGIN_DATE = getdate()" replace getdate() with "?

set @RPT_BEGIN_DATE =

9) Sav

10) Save your package. It should run now

Russ

Reply With Quote
  #3  
Old   
 
Posts: n/a

Default RE: Passing Global Variable into Execute SQL Task - 02-09-2004 , 02:49 PM



Russ,
That did the trick! Many thanks for your quick response!!
Scott

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.