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.