Further to the valid comments in solutions 1 and 2 here is some more advice...
1. Leave the formatting of output to the UI layer and not the data layer ... so instead of
TBLTRANSUSERS.FirstName + ' ' + TBLTRANSUSERS.LastName + '(' + TBLTRANSUSERS.UserCode + ')' as 'User Name'
just return all the parts required and let the business or UI layer format it accordingly. I.e.
TBLTRANSUSERS.FirstName, TBLTRANSUSERS.LastName, TBLTRANSUSERS.UserCode
The immediate benefit of this is that your code can be reused for cases where you don't want to concatenate the fields. It will also run more efficiently.
2. Especially do not convert dates to strings in your SQL. Very inefficient and it also means the calling code has to do a data conversion back to date.
Convert(Varchar(25),AssignedDate,131) as 'Assigned Date',
should just be
AssignedDate as 'Assigned Date',
3. Try to get out of the habit of using spaces in field names ('Assigned Date', 'User Name'). It's a real PITA having to use square brackets to refer the column name and can lead to hard-to-find errors being introduced into your code.
4. Be consistent! You have used Table Names to unambiguously identify many of your columns
except for
AssignedDate
... which table is that coming from? The same is true of the columns in the WHERE clause. You might also want to consider using short ALIAS names for tables - it will save some typing and can also make things a little clearer
5. This
(
SELECT RIGHT('0' + CAST(Datediff(second,AssignedDate,GetDate()) / 3600 AS VARCHAR),2) + ':' +
RIGHT('0' + CAST((Datediff(second,AssignedDate,GetDate()) / 60) % 60 AS VARCHAR),2) + ':' +
RIGHT('0' + CAST(Datediff(second,AssignedDate,GetDate()) % 60 AS VARCHAR),2
) as 'Elapsed Time'
is truly awful but in any event belongs in the UI layer. At most return the time difference in seconds if you really must.
Try applying these changes and compare the return from the SQL Profiler (
Run SQL Server Profiler | Microsoft Docs[
^] plus there are articles here on CodeProject)