Hello.

I am trying to get a summary total using the query below, but am met w/ '*Conversion Failed when converting the varchar value 'Total' to data type int*.'

Select

ln.LoanType,

ltd.LoanTypeINCDE,

ltd.LoanTypeDescription,

Total_Loans=Count(ln.LoanKey),

Total_OrignalAmount=SUM(ln.OriginalAmount),

Pay_Off = SUM(Case When ah.PrincipalAmount<0 Then ah.PrincipalAmount *-1 Else 0 End)

From

Loan ln

Join LoanTypeDefinitions ltd

On ltd.LoanType=ln.LoanType

Join AccountHistory ah

On ah.MemberNumber=ln.MemberNumber AND ah.AccountNumber=ln.LoanNumber

Where

ln.Closed=-1

AND Ln.LoanType IN ('7','27','42','43','1','4','45','47')

AND ln.CloseDate Between '10/01/2019' AND '10/31/2019'

AND ah.EntryDate Between '10/01/2019' AND '10/31/2019'

Group By

ln.LoanType,

ltd.LoanTypeINCDE,

ltd.LoanTypeDescription

Union

Select

'Total' As LoanType,

''As LoanTypeINCDE,

''As LoanTypeDescription,

Total_Loans=Count(ln.LoanKey),

Total_OrignalAmount=SUM(ln.OriginalAmount),

Pay_Off = SUM(Case When ah.PrincipalAmount<0 Then ah.PrincipalAmount *-1 Else 0 End)

From Loan ln

Join AccountHistory ah

On ah.MemberNumber=ln.MemberNumber AND ah.AccountNumber=ln.LoanNumber

Where

ln.Closed=-1

AND Ln.LoanType IN ('7','27','42','43','1','4','45','47')

AND ln.CloseDate Between '10/01/2019' AND '10/31/2019'

AND ah.EntryDate Between '10/01/2019' AND '10/31/2019'

Where am I going astray? Thank you.