select tctp.AccountDID, tp.rdbslicecode as [ProductSlice], Sum(isnull(tctp.Quantity,0)) as [ProductCount],
Max(CASE WHEN LevelCapability = 'RecruitEdgeRDB' THEN 'Named License' ELSE '' END ) AS [LicenseModel] into #ProductAudit from productdata.dbo.HHContractProduct
tctp with(nolock) inner join ProductData..hhproduct tp with(nolock) on tp.productid=tctp.productid where tctp.StatusCode='Active' and
tctp.LevelCapability in ('ResumeAccess','RDBSeat','RecruitEdgeRDB','NamedRDBAccess') and tctp.ActiveStartDT<=getdate() and
tctp.ActiveEndDT>=getdate() and tp.ProductID not in ('FM12RDB') and tp.RDBProductType<>'ViewBased' and tctp.AccountDID='AJ26106LNFG47J6YXMD'
Group by tctp.AccountDID, tp.rdbslicecode,tctp.LevelCapability
this query retun the result as below
AccDid productslice productcount licenseModel
===================================================================
AJ26106LNFG47J6YXMD US 1 Named License
AJ26106LNFG47J6YXMD US 1
but i want the result like below
AccDid productslice productcount licenseModel
===================================================================
AJ26106LNFG47J6YXMD US 2 Named License