Hi @Bone_12
I get exactly the same values as the column substring(apps.code,3,7)
With this OVER clause over (partition by substring(apps.code,3,7))
, you will always get the same Max Value.
Here is my guess based on your description, if it doesn't work, please provide more details including some sample data and your desired output.
Select Apps.name
,substring(apps.code,3,7)
,Max(case when comp.id = 1 and comp.val = 1 then comp.desc else substring(apps.code,3,7) end)as cust_id
From Dbo.apps Left join dbo.comps On apps.id = comps.id
Group by Apps.name,substring(apps.code,3,7)
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.