Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2006
    Posts
    31

    Unanswered: Redirect output to a file in MS SQL 2000

    Hi,

    Does someone know how to spool output of a query/procedure to a file? I'm running MS SQL 2000 and will have to set up an automated job which will email this file to interested parties. Here is the procedure that I'm executing:

    IF EXISTS (SELECT 1 FROM sysobjects WHERE [name] = 'sp_db_stats' AND type = 'P')
    DROP PROC sp_db_stats
    GO

    CREATE PROCEDURE sp_db_stats

    @DBName sysname = '*'
    AS
    DECLARE @DBStatus int,
    @dbid int

    DECLARE DBs CURSOR FOR
    SELECT name, dbid, status
    FROM master..sysdatabases
    FOR READ ONLY

    OPEN DBs
    FETCH NEXT FROM DBs INTO @DBName, @dbid, @DBStatus
    WHILE @@FETCH_STATUS = 0

    BEGIN
    exec master..sp_helpdb @DBName

    NextDB:
    FETCH NEXT FROM DBs INTO @DBName, @dbid, @DBStatus
    END

    CLOSE DBs
    DEALLOCATE DBs

    NoCursor:
    RETURN

    Thanks in advance!
    -Alla

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    moving thread from mysql forum to sql server forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    bcp... DTS... file system objects
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    From a command prompt (where you could execute a "dir c:\" command), you need to execute:
    Code:
    SQLCMD -E -Sservername -Q"EXECUTE master.dbo.sp_helpdb" -o "c:\filename.txt"
    -PatP

  5. #5
    Join Date
    Feb 2003
    Location
    India
    Posts
    216
    or u can configure sql-mail which can directly email results from any query passed as parameter.

  6. #6
    Join Date
    Nov 2006
    Posts
    31
    Unfortunately, I don't have SQLCMD procedure in the MS SQL 2000 version.

  7. #7
    Join Date
    Feb 2003
    Location
    India
    Posts
    216
    on SQL 2000 u use OSQL instead of SQLCMD. check Books Online for more

    Code:
    OSQL -E -Sservername -Q"EXECUTE MySP" -o "c:\filename.txt"

  8. #8
    Join Date
    Nov 2006
    Posts
    31
    It's strange enough but this procedure doesn't exist there too. What is the links for Books Online (I got redirected to the optimum online site). Thanks in advance.

    --Alla

  9. #9
    Join Date
    Sep 2003
    Location
    Los Angeles
    Posts
    103
    aka "GDMI" and "GDMI." and "GDMI.." !!! wtf!

  10. #10
    Join Date
    Feb 2003
    Location
    India
    Posts
    216
    i think u will have to re-install sql server. books online is online documentation of sql server and osql is a utility program. both automatically available if a minimum-installation is not selected during installation or not intentionally dropped during custom installation....

  11. #11
    Join Date
    Nov 2006
    Posts
    31
    Great, thanks a lot for your help!

Posting Permissions

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