Hola amigos, tengo la siguiente tabla, el cual muestra un documento y su
referencia, que tiene la siguiente lógica: El documento I-00003, tiene como
referencia a: I-00002 y este a su vez tiene como referencia a: I-00001 y el
documento I-00001, referencia a 5 documentos:
E-02973,E-02972,E-02971,E-02970,E-02969.
lo que quiero es ubicar todo el recorrido del documento digamos... E-02970,
osea debería tener una columna con los siguientes
datos:E-02970,I-00001,I-00002,I-00003, y almacenarlos en una tabla temporal,
para esto use la siguiente función, gracias por su ayuda
---Diana Florencia
ID | FECHA
|REFERENCIA|DOCUMENTO|---|-------------------------|----------|---------|26 |
2010-06-15 11:37:46.796 | E-02969 | I-00001 | 27 | 2010-06-15 11:37:47.875 |
E-02970 | I-00001 | 28 | 2010-06-15 11:37:48.968 | E-02971 | I-00001
| 29 | 2010-06-15 11:37:49.734 | E-02972 | I-00001 | 30 | 2010-06-15
11:37:50.484 | E-02973 | I-00001 | 31 | 2010-06-15 16:14:36.234 |
I-00001 | I-00002 | 32 | 2010-06-15 16:33:28.394 | I-00002 | I-00003 |
Create or Replace Function spDocCarpeta( Codigo Varchar)Returns SetOf
RefCursor As$Body$ Declare Lista RefCursor; CodDoc Varchar;
Registro Integer; Begin CodDoc := $1;
Create Temp Table Carpeta ( Doc
Varchar(15), Ref Varchar(15) ) On
Commit Drop; Select Count(RefDoc) Into Registro
From DocumentoReferencia Where RefDoc = CodDoc;
While Registro <> 0 Loop
Select DocId Into CodDoc From
DocumentoReferencia Where RefDoc = CodDoc;
Insert Into Carpeta Values (
$1, CodDoc
); End Loop;
FOR Lista IN SELECT doc FROM Carpeta LOOP
RETURN NEXT Lista; END LOOP;
Return Registro;
Commit; End;$Body$LANGUAGE 'plpgsql' VOLATILE;
Connect to the next generation of MSN Messenger Get it now!
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces.
It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us