Calculating Total Time in Seconds

The code is written for use in a named query, hence the colons for value parameters. You can’t run it in SSMS.

begin_ts and end_ts should be provided by your UI with date pickers or similar.