Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 1026

Re: Show only most recent data for group

$
0
0

I don't know the name of the Date field in TransEntry, so I assumed it was "EntryDate".  If it's not, you can change it in the below:

 

With maxEntryDate as (

  Select ItemID, max(EntryDate) as maxDate

  From TransEntry

  Group By ItemID

)

 

 

SELECT DISTINCT

  ClientSite.SiteName,

  Transactions.SiteTransID,

  Transactions.SiteTransDateTime,

  CustomerPri.FirstName,

  CustomerPri.Surname,

  Service.ServiceName,

  TransEntry.Amount,

  TransEntry.Discount,

  EmployeeDetails.Alias,

  EmployeeDetails_1.Alias

FROM   ShortcutsHOS.dbo.Service Service

  INNER JOIN ShortcutsHOS.dbo.TransactionItem TransactionItem

  ON Service.ServiceID=TransactionItem.ItemID

  INNER JOIN ShortcutsHOS.dbo.TransEntry TransEntry

    ON TransactionItem.ItemID=TransEntry.ItemID

  INNER JOIN maxEntryDate

    ON TransEntry.EntryDate = maxEntryDate.maxDate

  INNER JOIN ShortcutsHOS.dbo.Transactions Transactions

    ON TransEntry.TransactionID=Transactions.TransactionID

  INNER JOIN ShortcutsHOS.dbo.EmployeeDetails EmployeeDetails_1

    ON TransEntry.EmployeeID=EmployeeDetails_1.EmployeeID

  INNER JOIN ShortcutsHOS.dbo.EmployeeLocation EmployeeLocation

    ON EmployeeDetails_1.EmployeeID=EmployeeLocation.EmployeeID

  INNER JOIN ShortcutsHOS.dbo.ClientSite ClientSite

    ON EmployeeLocation.SiteID=ClientSite.SiteID

  AND Transactions.SiteID=ClientSite.SiteID

  INNER JOIN ShortcutsHOS.dbo.CustomerPri CustomerPri

  ON Transactions.CustomerID=CustomerPri.CustomerID

  INNER JOIN ShortcutsHOS.dbo.EmployeeDetails EmployeeDetails

  ON Transactions.SiteOperatorID=EmployeeDetails.EmployeeID

WHERE Transactions.SiteTransDateTime>={?StartDate} AND Transactions.SiteTransDateTime<{?EndDate}

ORDER BY ClientSite.SiteName, Transactions.SiteTransID

 

NOTE:  I also assumed that the dates were based on parameters.  See the best practices link I posted above for a complete explanation about how to use parameters in a command - you'll need to take them out of the Select Expert and remove them from the report altogether, then add them in the Command Editor and use them in the Where clause of the command.


Viewing all articles
Browse latest Browse all 1026

Trending Articles



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