Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Comparing ending date to current date

Author  Topic 

boc2
Starting Member

2 Posts

Posted - 2012-05-31 : 17:36:47
Please help, when I enter this

SELECT Assignment.StartDate, Assignment.EndDate, Park.Name
FROM Assignment WHERE Assignment.EndDate >= Convert(datetime, Convert(int, GetDate()))
INNER JOIN Park ON Park.ParkID=Assignment.ParkID";

I get a error "Incorrect syntax near the keyword 'INNER'"

Annie Boc2

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-05-31 : 17:39:38
Your query make little to no sense. Can you explain in words what you are trying to do? Also, maybe these links will help:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-31 : 17:40:07
SELECT Assignment.StartDate, Assignment.EndDate, Park.Name
FROM Assignment
INNER JOIN Park ON Park.ParkID=Assignment.ParkID
WHERE Assignment.EndDate >= Convert(datetime, Convert(int, GetDate()))

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

boc2
Starting Member

2 Posts

Posted - 2012-05-31 : 17:46:05
I have two table Assignment (startdate ,enddate , parkid) , park (parkid,name) I want to pull only the park's name where the project end date has not passed the current date. Asp.net is still showing me the error "Incorrect syntax near the keyword 'INNER'".

tkizer, I tried to switch the where statement but it still did not work.

Annie Boc2
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-31 : 17:58:05
quote:
Originally posted by boc2



tkizer, I tried to switch the where statement but it still did not work.




You'll need to expand on "did not work".

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-31 : 18:00:03
I don't understand your CONVERT. Try this instead:

SELECT Assignment.StartDate, Assignment.EndDate, Park.Name
FROM Assignment
INNER JOIN Park ON Park.ParkID=Assignment.ParkID
WHERE Assignment.EndDate >= DATEADD(d, DATEDIFF(d, 0, GetDate()), 0)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-05-31 : 18:09:46
I'm not sure about
quote:
I want to pull only the park's name where the project end date has not passed the current date.

But, maybe this will work....
SELECT 
Assignment.StartDate,
Assignment.EndDate,
Park.Name
FROM
Assignment
INNER JOIN
Park
ON Park.ParkID = Assignment.ParkID
WHERE
Assignment.EndDate <= CAST(SYSDATETIME() AS DATE)
Go to Top of Page
   

- Advertisement -