I have such a situation. I need to make a code work so that it selects only one PVISBN (Item Number) based on PVLICP (license plate) (I need to get only the first row from 2 that I am getting back).
TableSeven AS (
SELECT PVISBN, PVWHS, PVLICP, PVRZNE, PVRLOC, PVAZNE, PVALOC, PVLPRG,
ROW_NUMBER() OVER (PARTITION BY PVISBN, PVRZNE ORDER BY PVLICP --, PVRLOC, PVAZNE, PVALOC, PVLPRG
ASC) AS rn
FROM [REPIT].[LEVYDTA].[WHSPDVT]
WHERE PVSPDT BETWEEN @Last2WeekDATE AND @LWDate
--AND PVISBN='0164556221'
) ,
TableTwelve AS (
SELECT PVISBN, PVWHS, PVLICP, PVRZNE, PVRLOC, PVAZNE, PVALOC, PVLPRG, rn
FROM TableSeven
WHERE rn = 1
),
I keep getting 2 rows and should get only the 1st one
If someone may have an idea, I will appreciate.