QA: Results to File

  • Hi All,

    I'm interested, if there is a command I could place in the beginning of a T-SQL script to save its results to file - instead of choosing in QA menu Query -> Results to File? (By analogy with setting database either from toolbar or by placing 'use [database_name]' command)

    Thanks

    Anna Pimenova

  • Yep, that's already a feature of QA.

    Just click on the drop down box next to the execution mode (where you say whether the results should be in text or a grid), the bottom option is to file.

    Hope this helps

  • Sorry, I asked about the command (text) to type in the script that would do the same as choosing the option from the menu or drop down box.

    I'd like to make it easier to a person who will execute the script - so that he/she will not have to set any options by him/herself

  • you can use master..xpcmdshell with bcp.exe.  something like this

    for syntax pls refer to help on xp_cmdshell and bcp

    This may help you

  • Hi,

    For this you can check the link http://spaces.msn.com/members/sudheerpalyam/Blog/cns!1pKCMhBsSwPMevqFfdi-3JgQ!166.entry






    Regards,
    Sudheer 

    My Blog

  • you can execute the query like this in QA.  The output will be stored in the c:\file.txt

    DECLARE @cmd varchar(130)

    SET @cmd = 'bcp ' + '"' + 'select * from pubs..titles' + '"' + ' queryout c:\file.txt -U sa -P -c'

    exec master..xp_cmdshell @cmd , NO_OUTPUT

  • Would any user be able to use the preceeding method in QA? Or would they need permissions beyond SELECT to exec xp_cmdshell ?

    Thx.

     

  • OSQL?

  • It depends on whether the dba had set it so only sysadmin role members could use it.

Viewing 9 posts - 1 through 8 (of 8 total)

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