返回查询名称 Access SQL [英] Return query name Access SQL
问题描述
在一个已经存在的表中,我想创建一个包含我正在使用的查询名称的新列.
In an already existing table I would like to create a new column containing the name of the query I am using.
例如:
ID Name
-----------
1 Max
2 Jack
所需的输出是:
ID Name Query
-------------------
1 Max QueryName
2 Jack QueryName
推荐答案
我认为您可以在查询中使用静态值字段,如下所示:
I think you can use a static value field in your query, like this:
SELECT ID, NAME, "QueryName" AS Query
FROM yourTable;
<小时>
当您只想在查询表的结果中添加具有静态值的列时,上面是解决方案,如果您想创建一个具有特殊名称的查询em> 然后使用它,只需在创建时在其查询中使用其名称即可.
我的意思是当您更改查询名称时;还使用该名称编辑其查询.
When you just want to add a column with a static value in result of querying a table, above is the solution, If you want to create a Query with a special name then use it, just use its name in its query in creation time.
I mean when you are changing name of a query; also edit its query with using that name.
但是,我认为存储查询然后更改其名称并使用其名称作为其查询或其他查询的结果不是一个好主意,似乎您想在某处存储一个字符串值然后使用它通过将其添加到另一个查询中,所以:
But, I don't think this is a good idea to store a query then change its name and use its name as a result of its query or other queries, It seems you want to store a string value somewhere then use it by adding it in another query, So:
创建另一个表(QueryTable),例如:
Create another table(QueryTable) like:
QueryId | QueryName
--------+--------------
1 | Query Name 1
2 | Query Name 2
在您的其他查询中使用它:
Use it in your other queries:
SELECT t.*, q.QueryName
FROM yourTable t CROSS JOIN QueryTable q
WHERE q.QueryId = 1;
我建议这样做是因为最好在其使用区域使用工具,当您想存储数据并使用它时会产生一些信息;为此使用一张桌子.HTH ;).
And I suggest this because it's better to use a tool in its using zone, when you want to store data and use it result some information; use a table for that. HTH ;).
这篇关于返回查询名称 Access SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!