   declare
    @EntityID bigint = 271,  
    @StartDate datetime = '2023-1-26',  
    @EndDate datetime  = '2023-1-30'

  SELECT    
   pct.PettyCashType,
   coa.GLAccountName,
   ClerkIDName as CashierName,
   Comments,
   TotalAmount, 
   pcrs.Name as [Subject],
   pcrd.Name as [Department]  
FROM tbTransactionPettyCash tpc with (nolock)     
JOIN tbPettyCashType pct with (nolock) on tpc.PettyCashTypeID = pct.PettyCashTypeID    
LEFT JOIN LedgerChartOfAccounts coa on coa.GLAccountNumber=tpc.GLAccountNumber
LEFT JOIN tbPettyCashReimbursement pcr with (nolock) on tpc.TransactionPettyCashID = pcr.TransactionPettyCashId    
LEFT JOIN tbPettyCashReimburseSubject pcrs with (nolock) on pcr.SubjectId = pcrs.SubjectId
LEFT JOIN tbPettyCashReimburseDepartment pcrd with (nolock) on pcrd.DepartmentId = pcr.DepartmentId   
WHERE    
    EntityID = @EntityID AND     
    BusinessDay between @StartDate AND @EndDate     
ORDER BY PettyCashType, Transactiondate desc  
  
