I have the following query:

  • I have the following query:

    SELECT COL1,COL2

    FROM [SBA].DBO.[TABLE1]

    FOR XML RAW, ROOT('DATA')

    From the query above, how the query results, which is an xml can be stored in a folder?

    Previously I say thank you very much for your help

    king regards,

    Eko Indriyawan

  • Do you mean as a file? SQL Server doesn't write to files. You can call this from SQLCMD and output to a file.

  • Yes, you're right. What I mean is the file.

    Can you give an example to me to use SQLCMD in order to produce a file?

    King Regards,

    Eko Indriyawan

  • Submit something like this to SQLCMD:

    SET NOCOUNT ON;

    :XML ON

    SELECT COL1,COL2

    FROM [SBA].DBO.[TABLE1]

    FOR XML RAW, ROOT('DATA')

    So, from a Command window;

    SQLCMD -i "C:\PathAndFileNameOfAboveScript" -o "C:\PathAndFileNameForOuput"


    Have Fun!
    Ronzo

  • Ronzo has the type fo example that I would have given you. You can look up SQLCMD in Books Online and see examples.

    t-SQL works inside the server. It's not built to interact with the file system.

  • We are sorry, I still can not understand your explanation well. Are you willing to give more specific examples for me?

    I have tried but failed.

    Before I beg your pardon had made a lot of work.

    Warm regards,

    Eko Indriyawan

  • The first part of the example would be placed in a text file. That's why the second part has the file name as "c:ameandpathofabovescript"

    You create a text file that has the script you wish to run. Or the query. Then you submit that text file to SQLCMD as a parameter.

    This is from the command line. Please open Books Online, and look up SQLCMD.

  • Thanks a lot. I've tried it with the help of Books Online. I've managed to do it. But I have to use the SQLCMD Mode. Can I execute the query by using Stored Procedure?

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

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