macunte
macunte

Reputation: 465

SQL select how to insert column name and provide value

How do you add a column to a select statement and assign a static value, when the column does not exist?

name | address | vacationing | Zipcode

So for the example columns above, I would like to create the column on the fly of "vacationing" whose value will be assigned No for each record. I don't want to insert this column in the table permanently.

Thanks

Upvotes: 0

Views: 2382

Answers (3)

Dojo
Dojo

Reputation: 5704

select name, address, 'No' as vacationing, Zipcode from mytable;

Upvotes: 1

Kevin Aenmey
Kevin Aenmey

Reputation: 13429

Do you mean something like this?

SELECT Name, Address, 'No' AS Vacationing, Zipcode
FROM MyTable

Upvotes: 5

Chud37
Chud37

Reputation: 5027

You cannot have a column that only exists for some of the records, and not all of them. Either create it permanently or if you like, create another table and JOIN it using the name or id or whatever it is you use in this table as a primary key.

Upvotes: 0

Related Questions