tags:

views:

59

answers:

4

I have a select statement like this

select field1, field2  
  from table1

What I want is to have a newfield with only value "example".

newfield does not exist in the table, but when I run this query it kinda makes a virtual column with the values of example field.

+13  A: 
select field1, field2, 'example' as TempField
from table1

This should work across different SQL implementations.

Steve Homer
+1: For being first
OMG Ponies
+4  A: 

You mean staticly define a value, like this:

SELECT field1, 
       field2,
       'example' AS newfield
  FROM TABLE1

This will add a column called "newfield" to the output, and its value will always be "example".

OMG Ponies
+3  A: 

I'm rusty on SQL but I think you could use select as to make your own temporary query columns.

select field1, field2, 'example' as newfield from table1

That would only exist in your query results, of course. You're not actually modifying the table.

DA
A: 
select field1, field2, NewField = 'example' from table1 
priyanka.sarkar_2