troubleshooting Question

Conversion failed when converting the varchar value

Avatar of Abdul Khan
Abdul Khan asked on
Microsoft SQL Server
2 Comments1 Solution64 ViewsLast Modified:
Getting Conversion error when using the following code.

Declare @BeginDate datetime
Declare @EndDate datetime
Set @BeginDate = '03/01/2018'
Set @EndDate = '03/31/2018'

Select Count(AA.OrderD), BB.Age

from Livedb.dbo.AccountMain      AA

left join Livedb.dbo.Sales_Main     BB
    on AA.OrderID.PatientID=BB.OrderID
            
      where isnull(AA.DateTime1,AA.DateTime2)   between @BeginDate and @EndDate
            
      group by BB.Age
      
      Having  BB.Age > 17

Getting the following error when I use HAVING clause (it works without) :

Conversion failed when converting the varchar value '0m 17d' to data type int.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros