Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Select statement result set to large

$
0
0

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_numdlr_keyapp_dlr_fkeyRapAPPuser1vendid
559298.872818621NULL925697925697YouthServ               10174334000
559299.3218622NULL925697925697YouthServ               10174334000
559299.790718623NULL925697925697YouthServ               10174334000
559299.909518624NULL925697925697YouthServ               10174334000
559318.609956466NULL925697925697YouthServ               10174334000
559323.133752356NULL925697925697YouthServ               10174334000
559323.147218625NULL925697925697YouthServ               10174334000
559325.949418626NULL925697925697YouthServ               10174334000
559333.38154621NULL925697925697YouthServ               10174334000
559338.138118627NULL925697925697YouthServ               10174334000
559347.043652315NULL925697925697YouthServ               10174334000
559351.055918628NULL925697925697YouthServ               10174334000
559359.02255540NULL925697925697YouthServ               10174334000
559361.4418629NULL925697925697YouthServ               10174334000
559375.867318630NULL925697925697YouthServ               10174334000
559431.328818631NULL925697925697YouthServ               10174334000
559431.379418632NULL925697925697YouthServ               10174334000
559431.8118633NULL925697925697YouthServ               10174334000
559431.828118634NULL925697925697YouthServ               10174334000
559431.854418635NULL925697925697YouthServ               10174334000
559432.700718636NULL925697925697YouthServ               10174334000


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>