Solved

datepart not working

Posted on 2003-11-04
8
794 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP - How to insert data using sqlsrv on stored procedure? 8 61
CAST issue with SQL 2000 15 44
Removing SCCM 2016 4 53
sql trace 4 29
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

710 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