Solved

datepart not working

Posted on 2003-11-04
8
788 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
8 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Accepted Solution

by:
DrYRM earned 100 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

776 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