Search code examples
ms-accessms-access-2016

MS Access Database Multiple rows of static/constant data


So, this is a bit of a ridiculous questions, however, I have not been able to find an answer anywhere on the interwebs!

I have a MS Access DB which I am using in Access 2016. It is from a client and being used to provide data for another system.

Anyway, I am trying to mock some database data being returned from the table without changing the database data. So, I figured I would just do a select of constants, as I would in SQL or any other db language.

All I want returned is 2+ rows of data for 3 columns.

E.g. Name, Value, Target aaa, 1, 2, bbb, 3, 4, ccc, 5, 6, ...

I can do: SELECT 'aaa' AS [Name], 2 AS [Target], 3 AS [Value]

however, any other attempt I use to return more than one row of data just gives me errors. I've tried Unions, values(), multiple selects, etc, and none seem to work.

For sanity, can someone confirm that this is not possible, or am I missing something??

Many Thanks


Solution

  • You don't even need a custom table. You can hijack a system table:

    SELECT TOP 1 'aaa' AS [Name], 1 AS [Value]
    FROM MSysObjects
    UNION ALL
    SELECT TOP 1 'bbb' AS [Name], 2 AS [Value]
    FROM MSysObjects