Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2002
    Posts
    9

    Question Unanswered: Spool script from stored procedure

    Hi SQL Gurus,
    Is there a way to spool out script from within the stored procedure:

    Like
    sp_test
    ...
    ...
    begin
    ..
    spool c:\db.txt
    select name from sysdatabases
    go
    spool off
    spool c:\login.txt
    select name from syslogins
    go
    spool off

    end

    Any comments or suggestions are welcome.

  2. #2
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    Is "Spool" a way to setting output to a file?

    You could use xp_cmdshell

    Code:
    xp_cmdshell 'isql -E -Satlas -n -w5000 -Q"select * from sysdatabases" -oc:\db.txt'
    Then create a stored procedure with a bunch of xp_cmdshell commands one for each table.

  3. #3
    Join Date
    Jul 2002
    Location
    massachusetts
    Posts
    1

    Unhappy how do you output a file

    I have the same question.
    Did you figure it out?

  4. #4
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    you could always spin your own process

    Code:
    --------------------------------------------------------------------------------------------------
    create procedure Spool(
    @Filename nvarchar(500),
    @SQL nvarchar(3500))
    as
    declare @TSQL nvarchar(4000)
    set @TSQL = 'osql -E -n -w5000 -Q"' + @SQL + '" -o ' + @FileName
    exec master.dbo.xp_cmdshell @TSQL, no_output
    return 0
    go
    --------------------------------------------------------------------------------------------------

    Spool 'f:\temp.txt', 'select name from master.dbo.sysdatabases'
    Paul Young
    (Knowledge is power! Get some!)

Posting Permissions

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