I am not sure how to do this but I have a query that has unions in it. and i want to be able to diff each one by added a column. How do I add this column and give it a value. Thanks!
Select ID,Name,SpecialColumn = 'Test'
from table where ID = 'guid';
Use the string literal followed by a column alias 'Test' AS SpecialColumn
. This will produce the same value for all rows returned, useful for differentiating between UNION
components, or filling out mismatched column numbers between UNION
components when necessary.
SELECT
ID,
Name,
'Test' AS SpecialColumn
FROM table
WHERE ID = 'guid';
Output (ignoring your where clause) would be something like:
ID Name SpecialColumn
--------------------------
1 Venkman Test
2 Egon Test
1 Winston Test
3 Ray Test
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