Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select within a Select

Status
Not open for further replies.

amyl

Programmer
Sep 16, 2002
1
US
I'm trying to convert a ms sqlserver stored procedure into db2 sql.

In db2, can you have a select within a select?
For example,

Select t1.col,
Case col2
when '1' then
select t2.col3 from table 2 as t2
where t1.col = t2.col
else
'2'
END as column2
from
table1 as t1


 
Amyl,

It should be no problem, trhough Ialways put the sub-select in brackets

e.g.

Select t1.col,
Case col2
when '1' then
(select t2.col3 from table2 t2
where t1.col = t2.col)
else
'2'
END as column2
from
table1 as t1

The sub-query must be a singleton select (i.e. must only return 1 row)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top