在SELECT中包含实际不在数据库中的列

时间:2022-02-23 13:22:48

I'm trying to execute a SELECT statement that includes a column of a static string value. I've done this in Access, but never with raw SQL. Is this possible?

我正在尝试执行包含静态字符串值列的SELECT语句。我在Access中完成了这项工作,但从未使用原始SQL。这可能吗?

Example:

例:

 Name  | Status
 ------+--------
 John  | Unpaid
 Terry | Unpaid
 Joe   | Unpaid

In the above example, the "Status" column doesn't exist in the database.

在上面的示例中,数据库中不存在“状态”列。

1 个解决方案

#1


79  

You may want to use:

您可能想要使用:

SELECT Name, 'Unpaid' AS Status FROM table;

The SELECT clause syntax, as defined in MSDN: SELECT Clause (Transact-SQL), is as follows:

在MSDN:SELECT子句(Transact-SQL)中定义的SELECT子句语法如下:

SELECT [ ALL | DISTINCT ]
[ TOP ( expression ) [ PERCENT ] [ WITH TIES ] ] 
<select_list> 

Where the expression can be a constant, function, any combination of column names, constants, and functions connected by an operator or operators, or a subquery.

表达式可以是常量,函数,由运算符或运算符或子查询连接的列名,常量和函数的任意组合。

#1


79  

You may want to use:

您可能想要使用:

SELECT Name, 'Unpaid' AS Status FROM table;

The SELECT clause syntax, as defined in MSDN: SELECT Clause (Transact-SQL), is as follows:

在MSDN:SELECT子句(Transact-SQL)中定义的SELECT子句语法如下:

SELECT [ ALL | DISTINCT ]
[ TOP ( expression ) [ PERCENT ] [ WITH TIES ] ] 
<select_list> 

Where the expression can be a constant, function, any combination of column names, constants, and functions connected by an operator or operators, or a subquery.

表达式可以是常量,函数,由运算符或运算符或子查询连接的列名,常量和函数的任意组合。