Include in SELECT a column that isn't actually in the database

SqlSelect

Sql Problem Overview


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?

Example:

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

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

Sql Solutions


Solution 1 - Sql

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:

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCypherView Question on Stackoverflow
Solution 1 - SqlDaniel VassalloView Answer on Stackoverflow