Solved

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

Posted on 2016-10-25
1
28 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 47

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS  - Dropdown with Null 3 24
Why Delete * statement wont work with sql server ? 6 38
T-SQL: "HAVING CASE" Clause 1 23
Sql Server group by 10 26
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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 UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

786 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