Mittal
Mittal

Reputation: 41

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?

Upvotes: 1

Views: 1675

Answers (1)

SqlKindaGuy
SqlKindaGuy

Reputation: 3591

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

Upvotes: 3

Related Questions