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.
Microsoft SQL Server

Avatar of undefined
Last Comment
Abdul Khan

8/22/2022 - Mon