Solved

datepart not working

Posted on 2003-11-04
8
781 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
Comment Utility
Since you are using Access you might want to use the year function instead.

... and Year(DT)=2003
0
 

Expert Comment

by:charlotte1
Comment Utility
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
Comment Utility
Hello ,

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

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Accepted Solution

by:
DrYRM earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

771 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now