Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003
    Location
    Costa Rica
    Posts
    2

    Question Unanswered: Execute Script from File?

    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,108 8445,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.

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    try using osql or isql for running the script file. this can be invoked by using master..xp_cmdshell

  3. #3
    Join Date
    Oct 2003
    Posts
    1
    esto puede ejecutar el script de un archivo de texto,
    el ejemplo corre desde VB

    cnn.Execute "exec master..xp_cmdshell 'osql -r -U sa -P -S " & PvStrServidor & " -d " & PvStrNombreBD & " -i " & App.path & "\Archivo.SQL'"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •