简体   繁体   中英

Export SQL Table to CSV with Custom Header (Change in Header Name)

TABLE-A

Client_Code   Client_Name   POST_HC_STK
123              Sam           100
456              Lily          500
568              Maria         200
789              Champ         300

Want Table output as under in CSV File

Client Code  Client Name    Post Haircut Stock
123              Sam           100
456              Lily          500
568              Maria         200
789              Champ         300

How to export Table-A with a change in column header into a CSV?

Simply write a select where you give your columnnames another ALIAS.

You can use it 2 ways.

  1. You can export to CSV though your database in Management Studio
  2. You can add it as OLE DB Source in SSIS and then add a flat file destination which points to a CSV File.

SQL Query

SELECT 
Client_Code as [Client Code]
,Client_Name as [Client Name]
,POST_HC_STK as [Post Haircut Stock]
FROM TableA

You can also write it like this - Which in my opinon is easier to read:

SELECT 
[Client Code]        = Client_Code,
[Client Name]        = Client_Name,
[Post Haircut Stock] = POST_HC_STK
FROM TableA

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM