Hola estoy ejecutando el siguiente procedimiento y quisiera que al mismo tiempo los datos se inserten una una nueva tabla llamada sop_piq_log
ALTER procedure [dbo].[USP_BUSCAR_NUM_PIQ](
@PIQ INT,
@CMP varchar(15)
)
AS
BEGIN
IF(@PIQ = 0 )
BEGIN
SELECT sp.*
FROM [sop_piq] sp with(nolock)
WHERE sp.cmp = @CMP and sp.[status] in (2,3)
ORDER BY sp.[status] desc, sp.piq_number
INSERT INTO sop_piq_log([id], [oa], [date_ws], [hour_ws], [name], [type_document], [number_document], [cellphone], [age], [hcl], [oncological], [smoker], [diagnostic], [diagnostic_name], [region], [hospitalazation_type], [medical_report], [date_estimated], [duration_estimated], [hour_estimated], [created_at], [updated_at], [piq_number], [status], [cmp])
SELECT [id], [oa], [date_ws], [hour_ws], [name], [type_document], [number_document], [cellphone], [age], [hcl], [oncological], [smoker], [diagnostic], [diagnostic_name], [region], [hospitalazation_type], [medical_report], [date_estimated], [duration_estimated], [hour_estimated], [created_at], [updated_at], [piq_number], [status], [cmp]
FROM [sop_piq]
END
ELSE
BEGIN
SELECT sp.* FROM [sop_piq] sp with(nolock)
WHERE piq_number = @PIQ AND sp.cmp = @CMP
END
END
Sin embargo no logro que los datos se inserten en la tabla sop_piq_log
Gracias por su ayuda