I have been struggling with this for the past few days.
I am converting an Excel spreadsheet into a SSRS Report but the convenience of Excel's Vlookup is stopping me from producing repeatable results.
I am trying to join the first row of a table in a SQL statement.
Head
partnumber
==========
ABC123
XYZ999
Detail
account customer mapped
======= ======== ======
AA01 ABC123 POOL
UU08 ABC123 POOL
BH09 ABC123 POOL
AA01 XYZ999 CAR
I want to get the mapped value for each partnumber in the head table. I don't care that there are multiple account codes for each partnumber in the detail table - use just one of them is good enough.
My result should be
Result
partnumber mapped
========== ======
ABC123 POOL
XYZ999 CAR
I have read other Stack Overflow articles relating to this but I am having trouble translating it into my requirement SQL Server: How to Join to first row
A sample of my data is on http://sqlfiddle.com/#!6/32d6d/1
Can someone with more experience with SQL than me please explain what I am doing wrong?
Thank you