Solved

datepart not working

Posted on 2003-11-04
8
798 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

623 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