sql server - FULL OUTER JOIN is not working -
i need homecoming vendors regardless of whether there has been purchase vendor. query returning records vendor had purchase.
select vendors.name, iif([fundingsourceid] = 10, [amount], 0) credit, iif(( [fundingsourceid] = 2 ) or ( [fundingsourceid] = 3 ), [amount], 0) ebt, iif([fundingsourceid] = 4, [amount], 0) [match], cardpurchases.updateddate vendors total outer bring together cardpurchases on cardpurchases.vendorid = vendors.vendorid left bring together cardfundings on cardpurchases.cardfundingid = cardfundings.cardfundingid inner bring together marketevents on cardpurchases.marketeventid = marketevents.marketeventid inner bring together markets on marketevents.marketid = markets.marketid (cardpurchases.updateddate >= '10/22/2014' or cardpurchases.updateddate null) , (cardpurchases.updateddate < '10/23/2014' or cardpurchases.updateddate null) , (markets.marketid = 47 or markets.marketid null) order vendors.name
although have specified total outer bring together later in query restricting resultset based on columns in cardpurchases table causing vendors have no cardpurchases disappear.
you can either of following:
where ((cardpurchases.updateddate >= '10/22/2014' , cardpurchases.updateddate < '10/23/2014') or cardpurchases.updateddate null) , markets.marketid = 47
or
from vendors left bring together cardpurchases on cardpurchases.vendorid = vendors.vendorid , cardpurchases.updateddate >= '10/22/2014' , cardpurchases.updateddate < '10/23/2014')
sql-server outer-join
No comments:
Post a Comment