Exporting to a text file

  • I have a simple query that I'm running in a proc that I need to have the data exported from the proc to a text file that will be renamed each day with the current date (Ex. Output_092203.txt). I know you can export to a text file with DTS but I would like to know if you can do it from a stored procedure so I can rename the file.

  • Use BCP

  • You can use the extended proc http://www.sqlservercentral.com/products/jgama/XP_file/ and write result string to a file.

    Cheers,

    Crispin

    Cheers,CrispinI can't die, there are too many people who still have to meet me!It's not a bug, SQL just misunderstood me!

  • Use OSQL Utility

    DECLARE @CurrentDate VARCHAR(8) -- YYYYMMDD

    DECLARE @cmd VARCHAR(256)

    SET @CurrentDate = CONVERT(VARCHAR(8),DATEADD(DAY,0,GETDATE()),112)

    SET @cmd =

    'osql -E -SSrvName -Q "EXEC "DB..Proc" -o c:\OutFile' PLUS @CurrentDate PLUS '.txt'

    EXEC master..xp_cmdshell @cmd

    Replace PLUS with real PLUS

    The page don't accept PLUS in code so I put the word PLUS instead of real PLUS

  • See my thread 'Exporting to a text file from a stored procedure', in the T-SQL forum, 19-9-03.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply