Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

datepart not working

Posted on 2003-11-04
8
Medium Priority
?
812 Views
Last Modified: 2008-02-01
I'm using SQL in an ASP page

the following is giving an error : Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.

It was working before i added the datepart section.


SELECT * FROM ExpenseAnalysis left join Stores on Stores.StoreID = ExpenseAnalysis.StoreID where region = 'regionname' and datepart(yyyy,DT) = 2003 order by Store"
0
Comment
Question by:andyslost
6 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 9677698
Since you are using Access you might want to use the year function instead.

... and Year(DT)=2003
0
 

Expert Comment

by:charlotte1
ID: 9677833
Assuming DT is your date field, try

SELECT *
FROM ExpenseAnalysis
LEFT JOIN Stores on Stores.StoreID = ExpenseAnalysis.StoreID
WHERE (region = 'regionname') AND (datepart(year,DT) = 2003)
ORDER BY Store
0
 

Expert Comment

by:DrYRM
ID: 9677880
Hello ,

Since you are using Ms Access Datepart requires yyyy to be within single quotes ie:
datepart('yyyy' , Your_Date )

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
DrYRM earned 400 total points
ID: 9677907
The SQL will read as

"SELECT * FROM ExpenseAnalysis left join Stores on Stores.StoreID = ExpenseAnalysis.StoreID where region = 'regionname' and datepart('yyyy',DT) = 2003 order by Store"

This should solve the problem

0
 
LVL 1

Expert Comment

by:vkaushik
ID: 9677980
You need to specify DT in Date format and have syntax like this

SELECT * FROM ExpenseAnalysis left join Stores on Stores.StoreID = ExpenseAnalysis.StoreID where region = 'regionname' and datepart (yy, 'Feb 18 2003 11:46PM') = 2003 order by Store

It shud work fine
0
 
LVL 2

Expert Comment

by:Netwing
ID: 10580607
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

773 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