How to Setting two scalar variables in DB2 one SELECT/SET statement

407 views Asked by At

I can do this in MSSQL:

declare @id1 int
declare @id2 int

select @id1 = id1 , @id2 = id2 FROM dbo.table_id

In db2 this construction does't work and not work this

declare id1 int
declare id2 int
set id1,id2 = (SELECT id1, id2 FROM dbo.table_id)

I see only 2 solutions

  1. use 2 assignments
  2. generate a temporary table with two fields

How to do it more conveniently?

1

There are 1 answers

1
mao On BEST ANSWER

Db2 for inux/Unix/Windows allows this in inline SQL PL or stored-procedures:

declare id1 integer;
declare id2 integer;
set (id1, id2 ) = (select id1,id2 from dbo.table_id );