Adding to the comments above, there is no reason to have those sub-queries. You can do something like the following (although it is only marginally better)
UPDATE RRM SET IdRapportoMobile = @IdRapporto
FROM RisorsaRapportoMobile RRM
INNER JOIN RisorseUmane RU ON RU.IdRisorseUmane = RRM.IdRisorseUmane
WHERE RRM.IdRapportoMobile IS NULL
AND CONVERT(varchar(10), @Data, 105) = CONVERT(varchar(10), RU.Data, 105)
AND RU.IdCantiere = @IdCantiere
AND RU.IdUtenteInserimento = @IdUtente
See the comments about the use of CONVERT - get rid of those. Ensure @Data is a
date
(not a
datetime
.
Date
has been around since SQL2008 so it will work with 2014). If RisorseUmane.Data is a datetime on the database then try using
AND @Data = CAST(RU.Data AS date)
It should be faster than converting to strings.
You're joining tables on strings which isn't always the best - if you have scope to change that then it might help a little.
Temp tables will almost certainly help, as you will be limiting the data examined both in depth and width and you can also add indexes to the temp tables. Don't be tempted to use CTEs however.
There are some CodeProject articles that might also help you when it comes to tuning performance:
SQL Tuning Tutorial - Understanding a Database Execution Plan (1)[
^]
SQL Server Profiler Step by Step[
^]
How to Analyze SQL Server Performance[
^]