Setting a default value for a column in a select statement

Actually I have 2 tables table1 and table2

Table 1

name
city
addr.

table 2

name
city
addr.
ph.no

now the ph.no field is an additional field in table 2

so I want to show the ph.no field with the default value 12345 in the output of the select query in table1, since I want to add this output to the outfile. help me .. I am using db2 as400 database

+4
source share
2 answers

Yes you can do this:

SELECT name, city, addr, 12345 AS ph_no
FROM table1
+14
source

I know this thread is very old, but if someone needs an answer to a Nimmagadda question, you should accomplish this with something like:

SELECT name, city, addr, CASE name WHEN 'john' THEN 12345 WHEN 'peter' THEN 123 ELSE 0/*???? */END AS ph_no FROM table1

+1

Source: https://habr.com/ru/post/1760158/


All Articles