SQL – Mettre à jour un champ dans les résultats d'une procédure stockée

J'ai une procédure stockée avec une instruction UPDATE où je voudrais mettre à jour un champ dans les résultats d'une autre procédure stockée.

Première procédure stockée:

 ALTER PROCEDURE [dbo].[usp_sproc1] AS BEGIN SET NOCOUNT ON; SELECT * FROM Database1.dbo.tbl_dB1table AS t1 INNER JOIN Database2.dbo.tbl_dB2table AS t2 ON t1.field = t2.field INNER JOIN Database3.dbo.tbl_dB3table AS t3 ON t3.field2 = t1.field2 AND t3.field2 = t2.field2 INNER JOIN Database4.dbo.tbl_dB4table AS t4 ON t4.field3 = t2.field3 WHERE (field5 = 'c') AND (some_date IS NULL) END 

Deuxième procédure stockée:

 CREATE PROCEDURE [dbo].[usp_ASCRoadAmericaUpdateDateInternal] AS BEGIN SET NOCOUNT ON; UPDATE Database1.dbo.tbl_dB1table SET spr1.some_date = GETDATE() FROM (EXEC dbo.[usp_sproc1]) AS spr1 END 

Je veux donc récupérer le jeu de résultats de la première procédure stockée, puis mettre à jour le champ some_date dans Database1.tbl_dB1table avec la date du jour mais uniquement les loggings renvoyés par la première procédure stockée.

Est-il possible d'accomplir ceci sans dumping les résultats de la première procédure stockée dans un CURSOR et iterating par chaque logging?

 CREATE PROCEDURE dbo.usp_sproc2 AS BEGIN SET NOCOUNT ON; UPDATE t1 SET some_date = GETDATE() -- you probably mean CONVERT(DATE, GETDATE())? FROM Database1.dbo.tbl_dB1table AS t1 INNER JOIN Database2.dbo.tbl_dB2table AS t2 ON t1.field = t2.field INNER JOIN Database3.dbo.tbl_dB3table AS t3 ON t3.field2 = t1.field2 AND t3.field2 = t2.field2 INNER JOIN Database4.dbo.tbl_dB4table AS t4 ON t4.field3 = t2.field3 WHERE (field5 = 'c') AND (t1.some_date IS NULL); -------------^^^^^^ what table does this column come from? END GO