Hi there,
I'm getting duplicate records in my report due to a left join which is fine, however, I can't
figure out a formula to return the distinct records.
Here is the SQL for those interested:
SELECT "TransHeaders"."ID", "TransHeaders"."TransNo", "TransHeaders"."Branch",
"TransHeaders"."Station", "TransHeaders"."Logged",
TransHeaders.TransStatus, "B_Users"."LoginName", TransLines.IsVoided, TransLines.Line,
TransLines.SubAfterTax, "EventLog"."Logged", EventLog."Operation"
FROM "AKPOS"."dbo"."B_Users" "B_Users"
LEFT OUTER JOIN "AKPOS"."dbo"."TransHeaders" "TransHeaders"
ON ("B_Users"."LoginName"="TransHeaders"."TheUser" AND (Transheaders.Logged>={?StartDate}AND Transheaders.Logged<={?EndDate}))
LEFT OUTER JOIN "AKPOS"."dbo"."TransLines" "TransLines"
ON (TransLines.TransNo=TransHeaders.TransNo AND TransLines.Branch=TransHeaders.Branch AND TransLines.Station=TransHeaders.Station)
LEFT OUTER JOIN "AKPOS"."dbo"."EventLog" "EventLog"
ON (EventLog.TheUser=B_Users.LoginName AND (EventLog.Logged>={?StartDate}AND EventLog.Logged<={?EndDate}))
Effectively my report is returning something similar to the below:
LoginName ... TransID ... LineNo. ... EventLog(Operation)
..... 111 .......... 987 ........... 1 ............ 6/4/15 (ID=1)
..... 111 .......... 987 ........... 1 ............ 7/4/15 (ID=2)
..... 111 .......... 654 ........... 1 ............ 6/4/15 (ID=1)
..... 111 .......... 654 ........... 1 ............ 7/4/15 (ID=2)
..... 111 .......... 654 ........... 2 ............ 6/4/15 (ID=1)
..... 111 .......... 654 ........... 2 ............ 7/4/15 (etc.)
..... 111 .......... 654 ........... 3 ............ 6/4/15
..... 111 .......... 654 ........... 3 ............ 7/4/15
Where LineNo. is the line or item in a particular transaction and EventLog(Operation) is the date which which any logged events occurred.
What I'm trying to do is take each unique EventLog for each LoginName, which in the case above would be 2 events
occurring on the 6/4 and 7/4. Also I should add that I want to do a count for the number of distinct EventLog.Operation
per LoginName.
This is what I tried so far and I know it doesn't incorporate enough for it to work but I just can't figure out
how to achieve what I want:
/////HANDLES DUPLICATION OF RECORDS FOR EVENTLOG.OPERATION
/////****************************************************************
/////IE:For a user, each transaction line of every transaction is repeated
/////the number of times that an eventlog.operation occurred for the date period
If (isnull({OperatorReportCommand.ID}) AND isnull({OperatorReportCommand.Line})) then 0 else
If (({OperatorReportCommand.Line} = 1 OR isnull({OperatorReportCommand.Line}))
/////Reason for "isnull({OperatorReportCommand.Line})" is that if
/////a transaction has only 1 line then there is no line number associated
AND (PreviousIsNull ({OperatorReportCommand.Logged(1)}) OR
{OperatorReportCommand.Logged(1)} <> Previous ({OperatorReportCommand.Logged(1)})))
/////If the current datetime being tested doesn't equal the previous then continue
then 1 else 0
Hopefully someone smarter than I can help me!
Thanks
James
I'm getting duplicate records in my report due to a left join which is fine, however, I can't
figure out a formula to return the distinct records.
Here is the SQL for those interested:
SELECT "TransHeaders"."ID", "TransHeaders"."TransNo", "TransHeaders"."Branch",
"TransHeaders"."Station", "TransHeaders"."Logged",
TransHeaders.TransStatus, "B_Users"."LoginName", TransLines.IsVoided, TransLines.Line,
TransLines.SubAfterTax, "EventLog"."Logged", EventLog."Operation"
FROM "AKPOS"."dbo"."B_Users" "B_Users"
LEFT OUTER JOIN "AKPOS"."dbo"."TransHeaders" "TransHeaders"
ON ("B_Users"."LoginName"="TransHeaders"."TheUser" AND (Transheaders.Logged>={?StartDate}AND Transheaders.Logged<={?EndDate}))
LEFT OUTER JOIN "AKPOS"."dbo"."TransLines" "TransLines"
ON (TransLines.TransNo=TransHeaders.TransNo AND TransLines.Branch=TransHeaders.Branch AND TransLines.Station=TransHeaders.Station)
LEFT OUTER JOIN "AKPOS"."dbo"."EventLog" "EventLog"
ON (EventLog.TheUser=B_Users.LoginName AND (EventLog.Logged>={?StartDate}AND EventLog.Logged<={?EndDate}))
Effectively my report is returning something similar to the below:
LoginName ... TransID ... LineNo. ... EventLog(Operation)
..... 111 .......... 987 ........... 1 ............ 6/4/15 (ID=1)
..... 111 .......... 987 ........... 1 ............ 7/4/15 (ID=2)
..... 111 .......... 654 ........... 1 ............ 6/4/15 (ID=1)
..... 111 .......... 654 ........... 1 ............ 7/4/15 (ID=2)
..... 111 .......... 654 ........... 2 ............ 6/4/15 (ID=1)
..... 111 .......... 654 ........... 2 ............ 7/4/15 (etc.)
..... 111 .......... 654 ........... 3 ............ 6/4/15
..... 111 .......... 654 ........... 3 ............ 7/4/15
Where LineNo. is the line or item in a particular transaction and EventLog(Operation) is the date which which any logged events occurred.
What I'm trying to do is take each unique EventLog for each LoginName, which in the case above would be 2 events
occurring on the 6/4 and 7/4. Also I should add that I want to do a count for the number of distinct EventLog.Operation
per LoginName.
This is what I tried so far and I know it doesn't incorporate enough for it to work but I just can't figure out
how to achieve what I want:
/////HANDLES DUPLICATION OF RECORDS FOR EVENTLOG.OPERATION
/////****************************************************************
/////IE:For a user, each transaction line of every transaction is repeated
/////the number of times that an eventlog.operation occurred for the date period
If (isnull({OperatorReportCommand.ID}) AND isnull({OperatorReportCommand.Line})) then 0 else
If (({OperatorReportCommand.Line} = 1 OR isnull({OperatorReportCommand.Line}))
/////Reason for "isnull({OperatorReportCommand.Line})" is that if
/////a transaction has only 1 line then there is no line number associated
AND (PreviousIsNull ({OperatorReportCommand.Logged(1)}) OR
{OperatorReportCommand.Logged(1)} <> Previous ({OperatorReportCommand.Logged(1)})))
/////If the current datetime being tested doesn't equal the previous then continue
then 1 else 0
Hopefully someone smarter than I can help me!
Thanks
James