April 3, 2022 at 1:20 pm
I work on sql server 2017 i have issue i can't use count over partition instead of using having distinct
main statment i use
SELECT P.PartsFamilyID, P.PackageID, R.RoHSStatus
FROM Parts.ManufacturingData M WITH(NOLOCK)
INNER JOIN Parts.Nop_Part P WITH(NOLOCK) ON P.PartID = M.PartID
INNER JOIN Parts.ROHS R WITH(NOLOCK) ON R.ZPartID = P.PartID
where packageId is not null
GROUP BY P.PartsFamilyID, P.PackageID, R.RoHSStatus
HAVING COUNT(DISTINCT M.LeadFinishPlatingID) > 1 OR COUNT(DISTINCT M.BaseMaterialID) > 1
i need exactly rewrite statment above using count over partition with cte
with ctemanufacture as
(
)
select * into #test from rn1 > 1 or rn2>1
so please
How can i do that please ?
April 3, 2022 at 3:44 pm
What have you tried? This is you 171st post so you know what to do
April 4, 2022 at 2:42 am
Easy now... in this case, the OP has pretty much stated what they want to do. The problem with the HAVING is that it becomes difficult to select the rest of the row as in a SELECT *. I believe the op is asking without the "try" because he doesn't actually know what to try but does know that it can overcome the limitations of GROUP BY/HAVING.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply