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 2005 Forums
 Express Edition and Compact Edition (2005)
 sql statement

Author  Topic 

jdslim164
Starting Member

5 Posts

Posted - 2006-09-04 : 18:03:34
I plant lettuce in fields multiple times during the season. when i plant a trial it gets a wet date, lets just say 10-20-06. i need to go back to each planting 14 days after its been planted. How do i write the statement to display these lettuce trials.
i tried this statement
SELECT species, trialnum, wetdate
FROM mapdata
WHERE (wetdate = DATEADD([Day], - 14, GETDATE()))

Not sure what to try next.
jdslim

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-09-04 : 18:35:52
GETDATE() returns the time of the day as well.
Try;
WHERE DATEDIFF(DAY,wetdate,GETDATE())=14

rockmoose
Go to Top of Page

jdslim164
Starting Member

5 Posts

Posted - 2006-09-05 : 18:52:08
The statement you made makes more sense to me but im still getting an error message
Error Source: Microsoft JET Database Engine
Error Messge: Undefined function 'GETDATE' in function.

this is the actual statment in visual web developer
SELECT species, trialnum, wetdate FROM mapdata WHERE (DATEDIFF([DAY], wetdate, GETDATE()) = 14)

jdslim
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-09-05 : 19:29:38
Are you using MS Access or SQL Express? The error is thrown by the Jet Database Engine, which suggests Access. If you are using Access, then use the Date() function to get the date without a timestamp (or Now() if you need the timestamp).
Go to Top of Page

jdslim164
Starting Member

5 Posts

Posted - 2006-09-07 : 17:16:57
Yes i am using MS Access. i tried the statement with DATE() and NOW(), but this is the new error.

Executed SQL statement: SELECT species,trialnum,wetdate FROM mapdata WHERE (DATEDIFF([DAY], wetdate,DATE())=14)
Error Source: Microsoft JET Database Engine
Error Messge: No value given for one or more parameters.

jdslim
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-09-07 : 18:58:55
Look in the Access help file for the correct syntax for DateDiff(). It's not exactly the same as the SQL Server function, I think Day has to be in quotes (") and there are only certain abbreviations that are valid.
Go to Top of Page

nicku2d
Starting Member

1 Post

Posted - 2006-10-08 : 04:00:35
Hi jdslim...I have the same issue with sql referencing an access database (not lettuce related though!!) did you get your datediff search to work...the correct statement would bo oh so handy!! N

quote:
Originally posted by jdslim164

Yes i am using MS Access. i tried the statement with DATE() and NOW(), but this is the new error.

Executed SQL statement: SELECT species,trialnum,wetdate FROM mapdata WHERE (DATEDIFF([DAY], wetdate,DATE())=14)
Error Source: Microsoft JET Database Engine
Error Messge: No value given for one or more parameters.

jdslim



Because U2D is shorter than up 2 date marketing
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-09 : 10:06:20
Are you telling me this is not homework?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -