Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / IBM DB2, WebSphere, IMS, U2 [игнор отключен] [закрыт для гостей] / fetch first clause within subquery? / 5 сообщений из 5, страница 1 из 1
02.04.2007, 16:57
    #34431885
egoist.fish
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
fetch first clause within subquery?
How can I implement the following:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
select
  (select t2.name
  from table2 t2
  where t2.id=t1.id
  order by t2.id
  fetch first  1  row only)
from table1 t1
The row highlighted produce an error and I want only the first row from table2.
Thanks in advance.
...
Рейтинг: 0 / 0
02.04.2007, 16:58
    #34431889
egoist.fish
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
fetch first clause within subquery?
Sorry. OS/400 v5r3
...
Рейтинг: 0 / 0
02.04.2007, 18:36
    #34432306
Mark Barinstein
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
fetch first clause within subquery?
AFAIK there is no easy solution for this task in V5R3.
You can:
1. wrap subselect into external udf.
2. write sql udf where for each row from table1 you will select name from table2 for corresponding id into local variable and then insert this value into some temporary table.
Finally you can return select from this temporary table.
...
Рейтинг: 0 / 0
03.04.2007, 10:17
    #34433105
Mark Barinstein
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
fetch first clause within subquery?
Another way is to wrap scalar subselect into sql scalar udf:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
create function table2_udf(p_id int)
returns varchar( 255 )
language sql
begin atomic
 declare name varchar( 255 );

 select t.name into name
 from table2 t
 where t.id=p_id
 order by t.id
 fetch first  1  row only;

 return name;
end;

select table2_udf(id) name
from table1;
...
Рейтинг: 0 / 0
03.04.2007, 11:16
    #34433336
egoist.fish
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
fetch first clause within subquery?
Hi, Mark.
Yeapp. That is the way I am thinking of it for now. Just wondering if there is an elegant method :).
Thanks for your help.
...
Рейтинг: 0 / 0
Форумы / IBM DB2, WebSphere, IMS, U2 [игнор отключен] [закрыт для гостей] / fetch first clause within subquery? / 5 сообщений из 5, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]