Solved

Use GetDate function in SSIS in SQL Command?

Posted on 2015-01-30
5
341 Views
Last Modified: 2016-02-15
I have an ADO.NET Source in an SSIS package and want to run a SQL Command to bring back my records and I cant figure out how to write my Where clause where myfield = GetDate() and this does not work. Can someone let me know how I can return all the records where myfield = Today?

Please and Thank you
0
Comment
Question by:jknj72
5 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 40580524
>Where clause where myfield = GetDate()
GETDATE() is the datetime down to the milisecond (ish), so if you want just today without the time component then use CAST(GETDATE() as date)
0
 
LVL 12

Assisted Solution

by:Habib Pourfard
Habib Pourfard earned 250 total points
ID: 40580545
or you could write:
(DATEDIFF(d, myfield , GETDATE()) = 0)

Open in new window

0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40580765
btw Since you're using SSIS, it is a common practice to have an Execute SQL Task with SQL of 'SELECT GETDATE() as dt', then assign dt to an SSIS variable.  Then you have that variable to use elsewhere in your SSIS package, with any platform, and in expressions where you have to do things like rename an output file to include the current date.
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 40582308
try to make format

Where clause where    convert(nvarchar(10),myfield ,20)  =    convert(nvarchar(10), GetDate()  ,20)
0
 

Author Closing Comment

by:jknj72
ID: 40583833
thanks
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question