I need to add a dummy column to a simple select statement in certain circumstances:
Select Id, EndOfcol default '~' from Main where id > 40
The basic syntax for adding a new column is as follows: ALTER TABLE table_name ADD column_name data_type constraints; The SQL ALTER TABLE add column statement we have written above takes four arguments. First, we specify the name of our table.
A dummy column is one which has a value of one when a categorical event occurs and a zero when it doesn't occur. In most cases this is a feature of the event/person/object being described.
DUMMY is a public synonym for system table "SYS"."DUMMY" and what you should receive from there is via SQL is one row with a value 'X' for one column called "DUMMY" as well if select with SELECT * FROM "DUMMY"; Unless I missunderstood your question.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With