Solved

How can i compare the date field with sql get date function

Posted on 2016-10-25
1
15 Views
Last Modified: 2016-10-25
Hi Experts ,

I want to get all the rows with today date and select only those data . I have a field called Startdate . i want to compare those value with todays date using sql function and return todays date data only

SQL Query i tried
select ms.Id, ms.MailTemplate, ms.EmailAddress, ms.SchedulerName, ms.Module, ms.CustomViewId, ms.StartDateTime, ms.IsActive,mt.EmailBody, mt.TemplateName,mt.EmailSubject, v.ViewName from MailScheduler ms join MailTemplate mt on mt.Id=ms.MailTemplate join [Views] v on v.ID= ms.CustomViewId where ms.StartDateTime = GETDATE()  order by ms.Id desc 

Open in new window


Please see the attached screenshot
Thanks in Advance Experts
Capture.PNG
0
Comment
Question by:karthik80c
1 Comment
 
LVL 45

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41858418
If your StartDateTime can't be higher than today then use the following:
select ms.Id, ms.MailTemplate, ms.EmailAddress, ms.SchedulerName, ms.Module, ms.CustomViewId, ms.StartDateTime, ms.IsActive,mt.EmailBody, mt.TemplateName,mt.EmailSubject, v.ViewName 
from MailScheduler ms 
    join MailTemplate mt on mt.Id=ms.MailTemplate 
    join [Views] v on v.ID= ms.CustomViewId 
where ms.StartDateTime >= CAST(GETDATE() AS DATE)
order by ms.Id desc 

Open in new window

1

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now