same variable as input & output parameter in Execute SQL task

  • [font="Tahoma"]

    Hello Friends,

    I am using Execute SQL task for initializing the Start Date & End Date for the package. The StartDate & EndDate are included in the package as variables.

    My requirement is: Check the StartDate variable. If it is not NULL leave the StartDate & EndDate variables as they are. If the StartDate variable is NULL then Set the StartDate as the current month's first day and EndDate as the last day of the current month. So the month's first day and last day should be returned by the execute sql task.

    I have to logic to set the current month dates if the StartDate variable value is NULL..

    Please let me know how to implement this requirement using Execute SQL Task

    Thanks

    Murali

    [/font]

  • I'd use a script task instead of an execute sql task. It would be about 3 lines of c#.

  • You could use like that query to schedule it by the appropriate schedule

    declare @firstdate varchar (50)= convert (varchar (2),month (getdate()))+'/'+convert (varchar (2),29)+'/'+ convert (varchar (4),year (getdate()))

    declare @Endate varchar (50)

    if MONTH (getdate()) in (1,3,5,7,8,10,12)

    begin

    set @Endate= convert (varchar (2),month (getdate()))+'/'+convert (varchar (2),31)+'/'+ convert (varchar (4),year (getdate()))

    end

    else if MONTH (getdate())=2

    begin

    set @Endate= convert (varchar (2),month (getdate()))+'/'+convert (varchar (2),29)+'/'+ convert (varchar (4),year (getdate()))

    end

    else

    begin

    set @Endate= convert (varchar (2),month (getdate()))+'/'+convert (varchar (2),30)+'/'+ convert (varchar (4),year (getdate()))

    end

    select convert (datetime , @firstdate) as f, CONVERT (datetime, @Endate) as e

    if Firstdate is null or Firstdate =''

    update monthtable set Firstdate = CONVERT (datetime, @firstdate)

    if endate is null or endate =''

    update monthtable set ndate = CONVERT (datetime, @Endate)

    [font="Arial Black"]Performance Guard[/font]

    [font="Courier New"]Just ask me to get 0 sec for all queries[/font]

  • I think you should use the JavaScript instant of SQL statement. It is very easy as compare to sql statement logic.

  • Hi Thanks for your response.

    I already have the logic for finding the month start date and end date. Can you please help me in setting these values to the parameter.

    My situation here is that i need the startdate parameter as input to check for the null value first and if it is null then this parameter has to be set as output.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply