Hi @Mkontwana, Gcobani (EXTERN: VW S.Africa) ,
As mentioned by Erland, since you have [Transaction Code] columns in both tables, you have to identity which table it comes from.
Please refer below updated ones.
select
count([Station Description]) total,
stn.[Transaction Code],
[DateTime Passed]
from [Tracking_Server_DB].[dbo].TS_Station as stn
inner join [Tracking_Server_DB].[dbo].[Checkpoint Movement] as mv
on stn.[Transaction Code] = mv.[Transaction Code]
group by stn.[Transaction Code],[DateTime Passed]
order by [DateTime Passed] desc
OR
select distinct
count([Station Description]) over (partition by [DateTime Passed]) total,
stn.[Transaction Code],
[DateTime Passed]
from [Tracking_Server_DB].[dbo].TS_Station as stn
inner join [Tracking_Server_DB].[dbo].[Checkpoint Movement] as mv
on stn.[Transaction Code] = mv.[Transaction Code]
order by [DateTime Passed] desc
If above is still not working, please provide your CREATE TABLE statements for your tables together with INSERT statements with sample data, and the expected result of the sample. Then we could proceed to help you to enhance this query.
Thank you for understanding!
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.