81

How can I do in one select with multiple columns and put each column in a variable?

Something like this:

--code here
V_DATE1 T1.DATE1%TYPE;
V_DATE2 T1.DATE2%TYPE;
V_DATE3 T1.DATE3%TYPE;

SELECT T1.DATE1 INTO V_DATE1, T1.DATE2 INTO V_DATE2, T1.DATE3 INTO V_DATE3
FROM T1
WHERE ID='X';

--code here

3 Answers 3

170

Your query should be:

SELECT T1.DATE1, T1.DATE2, T1.DATE3
INTO V_DATE1, V_DATE2, V_DATE3
FROM T1
WHERE ID='X';
1
2
SELECT
    V_DATE1 = T1.DATE1,
    V_DATE2 = T1.DATE2,
    V_DATE3 = T1.DATE3
FROM T1
WHERE ID='X';

I had problems with Bob's answer but this worked fine

0
0

Select Into is used in Embedded SQL like SQLRPGLE. In SQL session like iSeries Navigator INTO clause is not allowed.

Embedded SQL select col1, col2 into:col1X, :col2X from T1 where ID ='X';

Online session(iSeries Nav or DbVeaver etc)

select col1 as Col1X, col2 as col2X from T1 where ID ='X';

1
  • 1
    If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Ana GH
    Mar 8, 2022 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.