For some reason I'm only returning one row when it comes to R while at SQL Server, I'm returning the correct number of rows. SQLDF:
CustomerCodingChangesT <- sqldf("
SELECT c.CustID as ID
, c.ReverseSupplier as Supplier
, c.ReverseCustomerCode as Code
, c.Name
, c.Address
, c.[From PostCode]
, c.[From Outlet]
, c.[From OutletName]
, o.FullAddress AS [From Address]
, c.[To PostCode]
, c.[To Outlet]
, c.[To OutletName]
, o1.FullAddress AS [To Address]
, MAX(CAST(c.TotalUnits AS VARCHAR)) AS [Total Units]
, '$'+MAX(CAST(c.TotalValue AS VARCHAR)) AS [Total Value]
, '' AS Checked
, c.CustRecActive as Active
FROM CustomerCorrectionSummaryT AS c
LEFT JOIN OutletMasterT AS o
ON c.[From PostCode] = o.Postcode
AND c.[From Outlet] = o.Outlet
LEFT JOIN OutletMasterT AS o1
ON c.[To PostCode] = o1.Postcode
AND c.[To Outlet] = o1.Outlet
ORDER BY c.totalvalue DESC;")
SQL:
if object_id ('tempdb..#CustomerCodingChanges') is not null drop table #CustomerCodingChanges
SELECT c.CustID as ID
, c.ReverseSupplier as Supplier
, c.ReverseCustomerCode as Code
, c.Name
, c.Address
, c.[From Postcode]
, c.[From Outlet]
, c.[From OutletName]
, o.FullAddress AS [From Address]
, c.[To Postcode]
, c.[To Outlet]
, c.[To OutletName]
, o1.FullAddress AS [To Address]
, CAST(c.TotalUnits AS VARCHAR(MAX)) AS [Total Units]
, '$'+CAST(c.TotalValue AS VARCHAR(MAX)) AS [Total Value]
, '' AS Checked
, c.CustRecActive as Active
INTO #CustomerCodingChanges
FROM #CustomerCorrectionSummary AS c
LEFT JOIN ndf_061.IRGMaster.dbo.OutletMaster AS o
ON c.[From Postcode] = o.postcode
AND c.[From Outlet] = o.outlet
LEFT JOIN ndf_061.IRGMaster.dbo.OutletMaster AS o1
ON c.[To Postcode] = o1.postcode
AND c.[To Outlet] = o1.outlet
ORDER BY c.totalvalue DESC;
Both dataframes for CustomerCorrectionSummaryT and OutletMasterT have the same number of results in R and in SQL Server so I don't know why it won't also show the same number of results in R versus in SQL Server. In SQL Server query returns 22 rows while in R I'm only getting one row which both are correct. R's sqldf just doesn't show all of it. I'm thinking it has something to do with my left join function but I don't really know. Let me know if you need more information!