Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Query Problem With DatePart

Posted on 2008-10-13
3
Medium Priority
?
219 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
[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
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
PaulKeating earned 2000 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 2000 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

Industry Leaders: 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

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.…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 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