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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Using Dates and Times in Queries

Author  Topic 

ewade
Starting Member

36 Posts

Posted - 2001-10-25 : 13:32:17
Let me preface this by saying that I'm an Access developer who is in the process of learning SQl Server, and I'm in desperate need of having a single question answered.

How do you reference the current system date and time in a query? My problem is this- I need to select a news article if the current date lies between the dates specified in two fields. This is acheived easily in Access by using the built-in NOW() function, as in the example below:


SELECT News.Headline, News.Article, News.DebutDate, News.ExpiryDate, News.LinkText, News.LinkURL
FROM News
WHERE (((News.DebutDate)<=Now()) AND ((News.ExpiryDate)>=Now()));


I have tried a number of things using GETDATE(), but none seem to work. How can I make this query work on SQL server?

ewade
Starting Member

36 Posts

Posted - 2002-02-20 : 14:36:35
Okay, now I feel like an idiot...

All this time I never knew about one of SQL server's charming little quirks...

My errors were caused by the fact that one of my fields was an ntext field. I didn't know that SQL server chokes on queries unless you put your variable-length fields at the end of the SELECT statement.

Problem solved, but I still wanted to say thank you to everyone- I can't believe how much I've learned from everyone here!

Never stop learning!
Go to Top of Page
   

- Advertisement -