-2

For SQL SELECT queries, we often have requests to include a field name in the csv output which does not exist in the database. (to match the format of another system\database, for example)

To handle this, I usually just edit the csv output file in Excel to add the extra column names as necessary. But there must be a simple method to accomplish this directly in the SQL query?

I don't want to alter the database in any way, the new column name would only be used for the query output. Also, there would not be any values for the result records- all results for this added field would be NULL.

Example: A database has TABLE1, with existing fields for Name, City, Phone.

Name     City         Phone
John     Princeton    333-444-5555
Paul     Denver       222-888-7777
Sarah    Detroit      987-654-3210

So I can query: select "Name", "City", "Phone" from TABLE1

But, is there a way to query so the results include a NewColumn name inserted, with null values for that field, so that output would look like this?

Name     City         NewColumn   Phone
John     Princeton                333-444-5555
Paul     Denver                   222-888-7777
Sarah    Detroit                  987-654-3210
StrayCatDBA
  • 2,173
  • 16
  • 23

1 Answers1

0
Select Name, City, '' AS [NewColumn], Phone from TABLE1
mustaccio
  • 28,207
  • 24
  • 60
  • 76