-1
SELECT 
    CASE WHEN EV878_ADDRESS_L1 = '' THEN NULL ELSE EV878_ADDRESS_L1 END AS [Street]
    ,NULL AS [HouseNumber]
    ,CASE WHEN EV878_ADDRESS_L2 = '' THEN NULL ELSE EV878_ADDRESS_L2 END AS [AddressAddition]
    ,CASE WHEN EV878_POSTAL_CODE = '' THEN NULL ELSE EV878_POSTAL_CODE END AS [PostalCode]
    ,CASE WHEN EV878_CITY = '' THEN NULL ELSE EV878_CITY END AS [City]
    ,CASE WHEN EV878_STATE = '' THEN NULL ELSE EV878_STATE END AS [State]
    ,CASE WHEN MM540_NAME_ALT1 = '' THEN NULL ELSE MM540_NAME_ALT1 END AS [Country]
    ,[EV878].EV878_REF_CODE AS [EBMS_EV878_REF_CODE]
    ,'included' AS [status] 
    ,GETDATE() AS [ModifiedDatetime]
sticky bit
  • 35,543
  • 12
  • 29
  • 39
  • 2
    Are you sure you use MySQL? the `[]` and `getdate()` makes it look more like it is SQL Server code. – sticky bit Mar 17 '20 at 12:46
  • 1
    Can you provide more details about what it is you want to achieve? It's not particularly clear. – Job Curtis Mar 17 '20 at 12:46
  • 2
    There's no `FROM` clause? But non literal columns... – sticky bit Mar 17 '20 at 12:46
  • Welcome to Stack Overflow. To help us help you, please take the [Tour](https://stackoverflow.com/tour) and read through [How To Ask](https://stackoverflow.com/help/how-to-ask). Take a look at this [well-structured question](https://stackoverflow.com/questions/60453346/use-or-conditions-in-where-clause-as-column-names-in-result), then [edit](https://stackoverflow.com/posts/60722696/edit) your question with the details needed to create [a Minimal, Complete, and Verifiable Example for database-related questions](https://dba.stackexchange.com/help/minimal-reproducible-example). – Eric Brandt Mar 17 '20 at 12:52

1 Answers1

1

welcome!

The way I see it, you want to create a table from a query, right? It seems the perfect usage of a VIEW.

A view is a virtual table based on the result-set of an SQL statement. It contains columns and rows derived from the query that created them. You can create views using the following syntax:

CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

So in your case, just use your select and you'll end up with a "table" that matches your case statement.

Hope this helps you!

fwerther
  • 108
  • 6