It’s been a while!

BOF

It’s been eight months since my last blog post, having taken on a new job, been on the receiving end of a full-on enterprise ransomware attack (that wasn’t nice!) and quite frankly experiencing one heck of a baptism of fire - I felt it was time do write a quick blog post tip!

In my new role, I haven’t had a lot of time or indeed need, to write many database queries.

However, recently I was asked if I could assist in the production of a simple SSRS report that displayed amongst other things, photos of students.

Having created a first draft, it soon became apparent that the photo I was pulling into the report, was the first photograph ever taken of the student on the system – this could have indeed been the correct one, or it may have been a photograph taken several years ago; as you can no doubt imagine, a pupil’s appearance can change a lot over several years!

The difficulty is that in iSAMS, you can’t simply write a query to get the latest photo; there isn’t a flag that states “this is the current photograph” (well, not that I am aware of anyway).

After some stackoverflow searching, I established that what was required was a “greatest-n-per-group” query.  Simply put, you want to link a table to another table, but ONLY display the latest record in the reference table, irrespective of how many rows there are per individual (e.g. you just want the latest photo of each student).

This is the full query that I used on iSAMS as the basis for the SSRS report.  The section that specifically deals with obtaining the latest photograph of the student, is highlighted.


  Show Comments