how to execute a script from a file in a store procedure?
example:
-- (* UPD: 08/07/2003 *)
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'pr_ExecScriptFF' AND type = 'P')
DROP PROCEDURE pr_ExecScriptFF
GO
--Ejecutar script desde un archivo.
CREATE PROCEDURE pr_ExecScriptFF @File varchar(500)
AS
BEGIN
EXEC ????sp_executesql???? @File
END
/* EJEMPLO
DECLARE @archivo varchar(500)
Set @archivo='c:\MyData\HO_ACT200307080924.sql'
EXECUTE pr_ExecScriptFF @archivo
*/
Note:
HO_ACT200307080924.sql:
--Inserts para la Tabla: HO_Energia
INSERT HO_Energia VALUES(171,'HO_1','25/06/2003','HO_2',1,1081783,1085080,1085875,1087590,1088445,1089820,NULL,1650,6387)
INSERT HO_Energia VALUES(172,'HO_1','14/06/2003','HO_1',1,993418,993418,993418,993418,993418,1000952,NULL,0,7534)
--Inserts para la Tabla: HO_RegHorario
INSERT HO_RegHorario VALUES(7683,'HO_1','8','25/06/2003 19:00:00',NULL)
INSERT HO_RegHorario VALUES(7684,'HO_2','8','25/06/2003 19:00:00',NULL)
etc....
:> I look in MSDN library for a sp_ but nothing...
*.sql may have 10000 lines.
tnx 4 help me.
example:
-- (* UPD: 08/07/2003 *)
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'pr_ExecScriptFF' AND type = 'P')
DROP PROCEDURE pr_ExecScriptFF
GO
--Ejecutar script desde un archivo.
CREATE PROCEDURE pr_ExecScriptFF @File varchar(500)
AS
BEGIN
EXEC ????sp_executesql???? @File
END
/* EJEMPLO
DECLARE @archivo varchar(500)
Set @archivo='c:\MyData\HO_ACT200307080924.sql'
EXECUTE pr_ExecScriptFF @archivo
*/
Note:
HO_ACT200307080924.sql:
--Inserts para la Tabla: HO_Energia
INSERT HO_Energia VALUES(171,'HO_1','25/06/2003','HO_2',1,1081783,1085080,1085875,1087590,1088445,1089820,NULL,1650,6387)
INSERT HO_Energia VALUES(172,'HO_1','14/06/2003','HO_1',1,993418,993418,993418,993418,993418,1000952,NULL,0,7534)
--Inserts para la Tabla: HO_RegHorario
INSERT HO_RegHorario VALUES(7683,'HO_1','8','25/06/2003 19:00:00',NULL)
INSERT HO_RegHorario VALUES(7684,'HO_2','8','25/06/2003 19:00:00',NULL)
etc....
:> I look in MSDN library for a sp_ but nothing...
*.sql may have 10000 lines.
tnx 4 help me.