Saving query results to pipe delimited or other formats

  • I want to save query result in pipe delimited form. I am wondering how to do it?

    By default, results to grid can be saved in csv format.

    I couldn't find a way to get result set in either pipe delimited form.

    Thanks,

  • The best way I can think of is to use the sqlcmd.exe. That allows you to format the output pretty much any way you want.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • If your using Microsoft Sql Server management studio this is Configurable.

    (actually almost the exact same in query analyzer)

    Tool--> Options -->Query Results --> Sql Server --> Results to Text.

    Change output format from Tab Delimited to Custom Delimited.

    Put a Pipe in the Custom Delimiter Box.

    Go back to your query select Query --> Results to File. Execute file, Give it a Disk path and a name.

    The file will be your name with a .rpt Extension, you can rename it to have a .txt extension.

    You obviously have to set the results to text value back to your previous setting if you don't want this permanently.

    Works good for a one time once in a while thing. but if you must generate this file frequently I would look at creating a SSIS Package. or as suggested above.

  • Thanks to both of you. Through your responses, i was able to do it. 🙂

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

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