Search code examples
hanahana-sql-script

Add a column to SQLScript result on HANA


I am facing following issue:

I had Tables

  1. A with columns: [ID, Name]
  2. B with columns: [ID, Name]

Now I want to UNION those two table with the Table result C:

C with columns [ID, Name, Source]

The Source column in Table C will shows value "A" or "B" to illustrate the source of that line is from Table A or B.

I tried some guides with

(SELECT *, "A" AS SOURCE FROM A) UNION ALL (SELECT *, "B" AS SOURCE FROM B)

But It still seems wrong!

Note: This is for SAP HANA. How I can do now ?


Solution

  • The problem with your query is the you used double quotes instead of single quotes for the content of the source column.

    Please change your query to:

    (SELECT *, 'A' AS SOURCE FROM A) UNION ALL (SELECT *, 'B' AS SOURCE FROM B)
    

    Then it should work