Solved

Query Problem With DatePart

Posted on 2008-10-13
3
206 Views
Last Modified: 2010-03-20
Hello,
I am attempting to filter my CaseNumber column (Text) by the first 2 digits by using the following SQL query and I keep getting an error.

SELECT     MAX(Mid(CaseNumber, 3, 6)) AS CaseValue
FROM         ServiceCalls
WHERE     (LEFT(CaseNumber, 2) = DatePart(yy, NOW()))
0
Comment
Question by:Gunit2507
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
PaulKeating earned 500 total points
ID: 22707110
LEFT() returns a string. DATEPART() returns an integer. I guess the message you are getting says "implicit conversion..."

Furthermore, DATEPART(yy ... ) returns a 4-digit year, not a 2-digit year as you seem to think: year and yyyy and yy  all mean the same thing.

GROUP BY CONVERT(INT, LEFT(CaseNumber, 2))
HAVING      CONVERT(INT(LEFT(CaseNumber, 2)) = (DatePart(yy, NOW())) % 100)

0
 
LVL 5

Assisted Solution

by:PaulKeating
PaulKeating earned 500 total points
ID: 22707136
Unmatched parens: fix is

GROUP BY CONVERT(INT, LEFT(CaseNumber, 2))
HAVING      CONVERT(INT, LEFT(CaseNumber, 2)) = (DatePart(yy, NOW()) % 100)
0
 

Author Comment

by:Gunit2507
ID: 22707228
This seems to work:

SELECT     MAX(Mid(CaseNumber, 3, 6)) AS CaseValue
FROM         ServiceCalls
WHERE     (LEFT(CaseNumber, 2) = RIGHT(DatePart('yyyy', NOW()), 2))
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

14 Experts available now in Live!

Get 1:1 Help Now