Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    4

    Question Unanswered: Send Select Statement to a File

    Problem with piping results of a select statement to a txt or ascii file in a stored procedure!

  2. #2
    Join Date
    Oct 2005
    Posts
    4

    Contiue the question:

    In dbisqlc one can say:

    SELECT * FROM SomeTable Where Field = 0 ># c:\file.txt

    Once I put the same statement in a stored procedure It resets the file to a blank file and the information does not get piped. This is the sp:

    /*============================================*/
    /* Stored Procedure : sp_ExportConduitRecords */
    /*============================================*/

    IF EXISTS (SELECT * FROM sysobjects WHERE name = 'sp_ExportConduitRecords')
    DROP PROCEDURE sp_ExportConduitRecords
    GO

    CREATE PROCEDURE Tableowner.sp_ExportConduitRecords(
    @completeVal smallint,
    @filePath varchar(64)= ''
    )
    AS

    SELECT * FROM ConduitComm WHERE Complete=@completeVal ># @filePath

    COMMIT

    GO

    GRANT EXECUTE ON sp_ExportConduitRecords TO Users



    Also, how can I append to an existing file?

    I appreciate any help in this matter.

    Thanks

  3. #3
    Join Date
    Feb 2004
    Location
    UK
    Posts
    43

    Use FSQL

    U can use fsql like this :

    fsql -D<DB Name> -U<user_id> -P<password> -S<Server Name> -c"exec <SP Name> " -I $SYBASE/interfaces > /tmp/file_name.csv

    Now u want to append the results if next time this SP executes....

    For this u can create one shell scipt. Now write the above fsql into .sh script and then so as file_name.csv created u can appened it to another file using normal unix cat command( like : cat file1 file2 >file3) everytime..

    Hope this will help u...

    ~Pankaj

Posting Permissions

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