Link to home
Create AccountLog in
Avatar of Abdul Khan
Abdul Khan

asked on

Conversion failed when converting the varchar value

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
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Abdul Khan
Abdul Khan

ASKER

Thanks so much, I should have paid more attention.