Formatting output for a select statement

  • Hello,

    I have a simple select statement which I want to have the output as comma separated with no column headers written to an output file.

    I have the output file portion but I was wondering if someone had experience with formatting output ? I could not seem to find any references to how to do this within a select statement.

    How can I get this statement to output csv with no column headings (Perhaps a set statement or something?)?:

    Select username, userType, keyinfo, userfirstname,userlastname,lastsystemhit,failedlogon,userdeleted

    from afsaweb_data.dbo.tbSiteUser Where userType='A'

    Please share your thoughts and expertise.

    Thanks in advance.

    Don

  • I know in SQL 2K you can go to the Query menu item in Query Analyzer and specify that the query be outputted in text.  The column headers will be there, but you can just copy the result set, without the column headers.  I hope that this helps.  Thanks.

    Chris

  • Actually there is a better way under the TOOLS|OPTIONS menu click the results tab. Change the results target to 'Reuslts to file..'  and Results output format to CSV.

     

    When you run the query you'll need to name the file somehting.csv

    You also have the options there to leave out the column headers, etc.

     

    You can play around with that a bit and see if it helps

  • You can do that which Jeff suggested, as well.  However,it is under the "Query" menu option, not "Tools".  Thanks.

    Chris

  • Depends on if you are using Enterprise Manager  or Management Stuido as your tool. In EM it is located under Tools|option. In 2k5's MS ist is located under both the Query|Query Options and Tools|Options

    As far as I know you can't set t ehoutput to CSV from just the Query menu. You can set resuylts to file from there, but the default output is an .rpt format which isn't what you need.  

  • Gotcha...thanks for the info, Jeff.

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

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