BCP out Column Headings

  • Is there a way to bcp out the column headings simuliar to the way you can in the UI within DTS?


    -JG

  • I'm not aware of anything simpler, but this should work:

    if object_id('workaround')>0

     drop view Workaround

    use pubs

    go

    create view Workaround as

    select

     au_id

     , au_lname

     , au_fname

     , phone

     , address

     , city

     , state

     , zip

     , convert(char, contract) 'contract'

     , 1 as SeqNo from authors

    union

    select

     'au_id'

     , 'au_lname'

     , 'au_fname'

     , 'phone'

     , 'address'

     , 'city'

     , 'state'

     , 'zip'

     , 'contract'

     , 0 as SeqNo

    go

    exec master..xp_cmdshell

     'bcp "select au_id, au_lname, au_fname, phone, address, city, state, zip,contract from pubs..Workaround order by SeqNo, au_id" queryout "C:\authors.txt"  -c  -T -SyourServer'

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

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