• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 533
  • Last Modified:

Use GetDate function in SSIS in SQL Command?

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
jknj72
Asked:
jknj72
2 Solutions
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>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
 
Habib PourfardSoftware DeveloperCommented:
or you could write:
(DATEDIFF(d, myfield , GETDATE()) = 0)

Open in new window

0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
 
Kamal KhaleefaInformation Security SpecialistCommented:
try to make format

Where clause where    convert(nvarchar(10),myfield ,20)  =    convert(nvarchar(10), GetDate()  ,20)
0
 
jknj72Author Commented:
thanks
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now