SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to create variable for @startdate and @endDate in SSIS Execute SQL Task


How to create variable for @startdate and @endDate in SSIS Execute SQL Task

Author
Message
gissah
gissah
SSC Veteran
SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)

Group: General Forum Members
Points: 274 Visits: 329
I have a simple query that provide me with all the previous month data using the FilecreationDate

Declare @StartDate varchar(8)
Declare @EndDate varchar(8)

Set @StartDate = Replace(convert (varchar(8), DATEADD(dd,-(DAY(DATEADD(mm,1,GETDATE()))-1),DATEADD(mm,-1,GETDATE())),112),'/','')

Set @EndDate = Replace(convert(varchar(8), DATEADD(dd, -DAY(DATEADD(m,1,GETDATE())), DATEADD(m,0,GETDATE())),112),'/','')

Select * FROM mytable
where FilecreationDate between @StartDate and @EndDate

I want to use the above query to export the previous month data using the Execute sql task

Variables:
StartDate value Replace(convert (varchar(8), DATEADD(dd,-(DAY(DATEADD(mm,1,GETDATE()))-1),DATEADD(mm,-1,GETDATE())),112),'/','')

EndDate value Replace(convert(varchar(8), DATEADD(dd, -DAY(DATEADD(m,1,GETDATE())), DATEADD(m,0,GETDATE())),112),'/','')

My query in Execute SQL Task
Select * FROM [dbo].[myTable]
where FileCreationDate between ? and ?

when I build my ssis and run I get every record from the table. what am I doing wrong. It looks like my variable parameter is not working. All I want are only records from the 1st of last month to the end of last month.
gissah
gissah
SSC Veteran
SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)SSC Veteran (274 reputation)

Group: General Forum Members
Points: 274 Visits: 329
I have solve my issue. I did not need Execute SQL Task. I used sqlcommand
below86
below86
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1716 Visits: 2711
Just an FYI if you are using the CONVERT with 112 you don't need the REPLACE statement the 112 does not return the results with the slashes(yyyymmdd).

-------------------------------------------------------------
we travel not to escape life but for life not to escape us
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search