SQL: Is it possible to add a dummy column in a select statement?
I need to add a dummy column to a simple select statement in certain 开发者_开发百科circumstances:
Select Id, EndOfcol default '~' from Main where id > 40
Yes, it's actually a constant value.
SELECT id, '~' AS EndOfcol
FROM Main
WHERE id > 40
Sometimes you may want to cast the datatype of the constant especially if you plan to add other data to it later:
SELECT id, cast('~' as varchar(20)) AS EndOfcol FROM Main WHERE id > 40
This is especially useful if you want to add a NULL column and then later figure out the information that goes into it as NULL will be cast as int automatically.
SELECT id, cast(NULL as varchar(20)) AS Myfield FROM Main WHERE id > 40
Yes, it is possible it can be constant or can be conditional
SELECT id, '~' EndOfcol FROM Main WHERE id > 40
An easy solution is to add a column like this:
Select Id, EndOfcol default '~', space(2) as Dummy from Main where id > 40
精彩评论