Vitaliy Kushneruk
Vitaliy Kushneruk

Reputation: 48

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

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?

Upvotes: 1

Views: 489

Answers (1)

mao
mao

Reputation: 12267

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 );

Upvotes: 1

Related Questions