How do I query for all dates greater than a certain date in SQL Server

0 votes

I tried this:

SELECT * 
FROM dbo.March2010 A
WHERE A.Date >= 2010-04-01;

But it's not working. Can someone please help me with this?

Aug 29, 2022 in Database by Kithuzzz
• 38,000 points
934 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Try this:

select *  
from dbo.March2010 A 
where A.Date >= Convert(datetime, '2010-04-01' )

2010-4-01 is considered as a mathematical expression in your query, thus in essence, it reads

select *  
from dbo.March2010 A 
where A.Date >= 2005; 

(2010 minus 4 minus 1 is 2005 Converting it to a proper datetime, and using single quotes will fix this issue.)

Technically, the parser might allow you to get away with:

select *  
from dbo.March2010 A 
where A.Date >= '2010-04-01'

it will do the conversion for you, but in my opinion, it is less readable than explicitly converting to a DateTime for the maintenance programmer that will come after you.

answered Aug 30, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Database

0 votes
1 answer

How do I obtain a Query Execution Plan in SQL Server?

There are several ways to get an ...READ MORE

answered Sep 20, 2022 in Database by narikkadan
• 63,600 points
1,607 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,070 points
924 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4, 2022 in Database by Vaani
• 7,070 points
621 views
0 votes
0 answers
0 votes
0 answers

How do I list all the columns in a table?

For the various popular database systems, how ...READ MORE

Aug 9, 2022 in Database by Kithuzzz
• 38,000 points
600 views
0 votes
0 answers

How can I show the table structure in SQL Server query?

Query: SELECT DateTime, Skill, Name, TimeZone, ID, User, ...READ MORE

Aug 11, 2022 in Database by Kithuzzz
• 38,000 points
873 views
0 votes
1 answer

How Can I use "Date" Datatype in sql server?

There's problem in all of them and ...READ MORE

answered Feb 9, 2022 in Database by Neha
• 9,020 points
1,474 views
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

Timestamp is a synonym for rowversion, according ...READ MORE

answered Feb 16, 2022 in Database by Vaani
• 7,070 points
5,127 views
0 votes
1 answer

How to convert DateTime to VarChar

With Microsoft Sql Server: -- -- Create test case -- DECLARE ...READ MORE

answered Feb 23, 2022 in Database by Neha
• 9,020 points
1,323 views
0 votes
1 answer

How Can I use "Date" Datatype in sql server?

Your dates are interpreted as MM-DD-YYYY. This ...READ MORE

answered Jun 21, 2022 in Others by nisha
• 2,210 points
689 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP