I have a stored procedure:
CREATE PROCEDURE MyProc
(
@Param1 [datetime],
@Param2 [nvarchar](20),
@Param3 [nvarchar](20),
@Param4 [nvarchar](20),
@Param5 [nvarchar](20),
)
AS
BEGIN
INSERT INTO MyTable1
(
Field1,
Field2,
Field3,
Field4,
Field5
)
SELECT
@Param1,
@Param2,
@Param3,
Field12,
'constantValue'
FROM MyTable2
WHERE Field13 = @Param4
END
How could I change the stored proc in order it inserts into the Field5 of MyTable1 not the constantValue but a result of yet another query to MyTable2 with the last parameter (@Param5)?
I.e.:
FROM MyTable2
WHERE Field13 = @Param5
Field12but from different records ofMyTable2