Hi
I am not sure how to pose this question but here goes.
I have a select statement joining tables from two databases where the result set returns matches for every occurrence of the items in the select portion. I am not sure how to write the query to only match for a single occurrence of an id field in one of the tables (like vendid). Any suggestions would be appreciated, thanks.
Query:
Select distinct d.dlr_reference_num,d.dlr_key,a.app_dlr_fkey, CONVERT(VARCHAR(30), a.app_key)AS RapAPP, c.user1, c.vendid from NJACCOUNTING01.marlin_test.dbo.apdoc
c inner join dbo.application a
on CONVERT(VARCHAR(30), a.app_key) = SUBSTRING(c.user1, 1,6) , dbo.dealer d
where c.DocType = 'VO' and c.Crtd_DateTime > '2012-01-01 00:00:00' and c.VendId like '01%'
Sample result set:
dlr_reference_num | dlr_key | app_dlr_fkey | RapAPP | user1 | vendid |
559298.8728 | 18621 | NULL | 925697 | 925697YouthServ | 10174334000 |
559299.32 | 18622 | NULL | 925697 | 925697YouthServ | 10174334000 |
559299.7907 | 18623 | NULL | 925697 | 925697YouthServ | 10174334000 |
559299.9095 | 18624 | NULL | 925697 | 925697YouthServ | 10174334000 |
559318.6099 | 56466 | NULL | 925697 | 925697YouthServ | 10174334000 |
559323.1337 | 52356 | NULL | 925697 | 925697YouthServ | 10174334000 |
559323.1472 | 18625 | NULL | 925697 | 925697YouthServ | 10174334000 |
559325.9494 | 18626 | NULL | 925697 | 925697YouthServ | 10174334000 |
559333.381 | 54621 | NULL | 925697 | 925697YouthServ | 10174334000 |
559338.1381 | 18627 | NULL | 925697 | 925697YouthServ | 10174334000 |
559347.0436 | 52315 | NULL | 925697 | 925697YouthServ | 10174334000 |
559351.0559 | 18628 | NULL | 925697 | 925697YouthServ | 10174334000 |
559359.022 | 55540 | NULL | 925697 | 925697YouthServ | 10174334000 |
559361.44 | 18629 | NULL | 925697 | 925697YouthServ | 10174334000 |
559375.8673 | 18630 | NULL | 925697 | 925697YouthServ | 10174334000 |
559431.3288 | 18631 | NULL | 925697 | 925697YouthServ | 10174334000 |
559431.3794 | 18632 | NULL | 925697 | 925697YouthServ | 10174334000 |
559431.81 | 18633 | NULL | 925697 | 925697YouthServ | 10174334000 |
559431.8281 | 18634 | NULL | 925697 | 925697YouthServ | 10174334000 |
559431.8544 | 18635 | NULL | 925697 | 925697YouthServ | 10174334000 |
559432.7007 | 18636 | NULL | 925697 | 925697YouthServ | 10174334000 |