123

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.

1 Answer 1

222

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.

3
  • 7
    You actually want (in this case) 'Unpaid' AS Status
    – Joe
    Mar 23, 2010 at 22:48
  • 1
    @Joe: Thanks, that would be a better example in fact. Fixed answer. Mar 23, 2010 at 22:49
  • Ah, an alias with a static value... that makes so much sense after the fact of course. Thanks so much. :)
    – Cypher
    Mar 23, 2010 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.