Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 31-10-2014
jars jars is offline
Miembro
 
Registrado: mar 2004
Posts: 279
Poder: 21
jars Va por buen camino
External Data Souce

Hola amigos.
Tengo una SP en la que necesito extraer un dato que esta en otra BBDD.
Lo hago asi:

Código SQL [-]
execute statement 'select user_login from users where userid = :userid'
on external data source '192.168.x.x:sched'
as user 'SYSDBA'
password 'masterkey'
into :userlogin

Esto siempre me da el error "Cannot find table attach"
Aclaro que sched es el alias de la bbdd.

Alguna ayuda?
Gracias
Responder Con Cita
  #2  
Antiguo 01-11-2014
Avatar de Young
Young Young is offline
Miembro
 
Registrado: abr 2006
Ubicación: San Felipe, Chile
Posts: 86
Poder: 18
Young Va por buen camino
Estimado, ¿ambas bases de datos están en la misma maquina?, de ser así ¿has probado poner la ruta completa a la base de datos? y por último aunque obvio el nombre de la tabla es el correcto?

Saludos.
Responder Con Cita
  #3  
Antiguo 01-11-2014
jars jars is offline
Miembro
 
Registrado: mar 2004
Posts: 279
Poder: 21
jars Va por buen camino
Hola young, ambas bases estan en la misma pc y ya probe con el path y nada.
El nombre de la tabla es correcto.
Responder Con Cita
  #4  
Antiguo 01-11-2014
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.021
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Pon el código completo que lo veamos.
Responder Con Cita
  #5  
Antiguo 01-11-2014
jars jars is offline
Miembro
 
Registrado: mar 2004
Posts: 279
Poder: 21
jars Va por buen camino
Este es el codigo completo:

Código SQL [-]CREATE OR ALTER PROCEDURE SP_AGN_PERF ( pdatefrom varchar(8), pdateto varchar(8), ptimefrom varchar(6), ptimeto varchar(6), psectorid integer) returns ( agentfullname varchar(30), agentid varchar(10), skill smallint, i_received smallint, i_answered smallint, i_short smallint, i_returned smallint, i_talktime char(10), logintime char(10), idletime char(10), oreceived smallint, oanswered smallint, oshort smallint, oreturned smallint, otalktime char(10), userid integer) as declare variable script1 varchar(5000); declare variable tmpagentid varchar(10); declare variable lwhere varchar(1024); declare variable tmplogin integer; declare variable tmpidle integer; declare variable tmp_i_talk integer; declare variable tmp_o_talk integer; declare variable scrpt varchar(100); begin -- Inicializa las vari agentfullname = ''; agentid = ''; skill = 0; i_received = 0; i_answered = 0; i_short = 0; i_returned = 0; i_talktime = '00:00:00'; logintime = '00:00:00'; idletime = '00:00:00'; o_received = 0; o_answered = 0; o_short = 0; o_returned = 0; o_talktime = '00:00:00'; userid = 0; LWHERE = 'logdate between '''|| pdatefrom ||''' and '''||pdateto ||''' ' || 'and logtime between '||ptimefrom||' and '||ptimeto; if ((P_SECTORID is not NULL) and (P_SECTORID > 0)) then LWHERE = :LWHERE||' and sectorid = '||:P_SECTORID; script1 = 'select userid, agentid, skill, ' || 'Sum(Case when calltype = ''I'' then 1 else 0 end), ' || 'Sum(Case when calltype = ''I'' and talktime > 0 then 1 else 0 end), ' || 'Sum(Case when calltype = ''I'' and talktime between 1 and 20 then 1 else 0 end), ' || 'Sum(Case when calltype = ''I'' and talktime = 0 and delaytime > 0 then 1 else 0 end), ' || 'Sum(Case when calltype = ''I'' then talktime + holdtime + cnsholdtime else 0 end), ' || 'Sum(Case when calltype = ''O'' then 1 else 0 end), ' || 'Sum(Case when calltype = ''O'' and talktime > 0 then 1 else 0 end), ' || 'Sum(Case when calltype = ''O'' and talktime between 1 and 20 then 1 else 0 end), ' || 'Sum(Case when calltype = ''O'' and talktime = 0 and delaytime > 0 then 1 else 0 end), ' || 'Sum(Case when calltype = ''O'' then talktime + holdtime + cnsholdtime else 0 end) ' || 'from logpos ' || 'where '||LWHERE|| ' group by userid, agentid, skill order by agentid, skill'; for execute statement script1 into :userid, :agentid, :skill, :i_received, :i_answered, :i_short, :i_returned, :tmp_i_talk, oreceived, oanswered, oshort, oreturned, :tmp_o_talk do begin select sum(interval_t), sum(idletime) from logposint where userid = :userid and (logdate between pdatefrom and pdateto) and (logtime between ptimefrom and ptimeto) into :tmplogin, :tmpidle; select * from sp_secsto_hhmmss(:tmplogin) into logintime; select * from sp_secsto_hhmmss(:tmpidle) into idletime; select * from sp_secsto_hhmmss(:tmp_i_talk) into i_talktime; select * from sp_secsto_hhmmss(:tmp_o_talk) into o_talktime; execute statement 'select user_fullname from users where userid = :userid' on external data source '192.168.x.x:sched' as user 'SYSDBA' password 'masterkey' into :agentfullname; suspend; end end


Espero encuentren donde esta el problema.
Gracias-
Responder Con Cita
  #6  
Antiguo 01-11-2014
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.021
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Lo he humanizado un poco

Por cierto, te aconseja que "dividas y vencerás", porque eso así, a lo bruto, es inmasticable.

Código SQL [-]
CREATE OR ALTER PROCEDURE SP_AGN_PERF ( pdatefrom varchar(8), pdateto varchar(8), 
                                        ptimefrom varchar(6), ptimeto varchar(6), psectorid integer) 
  returns ( agentfullname varchar(30), agentid varchar(10), skill smallint, i_received smallint, i_answered smallint, 
            i_short smallint, i_returned smallint, i_talktime char(10), logintime char(10), idletime char(10), 
            oreceived smallint, oanswered smallint, oshort smallint, oreturned smallint, otalktime char(10), userid integer) 
as 
  declare variable script1 varchar(5000); 
  declare variable tmpagentid varchar(10); 
  declare variable lwhere varchar(1024); 
  declare variable tmplogin integer; 
  declare variable tmpidle integer; 
  declare variable tmp_i_talk integer; 
  declare variable tmp_o_talk integer; 
  declare variable scrpt varchar(100); 
begin -- Inicializa las vari 
  agentfullname = ''; 
  agentid = ''; 
  skill = 0; 
  i_received = 0; 
  i_answered = 0; 
  i_short = 0; 
  i_returned = 0; 
  i_talktime = '00:00:00'; 
  logintime = '00:00:00'; 
  idletime = '00:00:00'; 
  o_received = 0; 
  o_answered = 0; 
  o_short = 0; 
  o_returned = 0; 
  o_talktime = '00:00:00'; 
  userid = 0; 
  LWHERE = 'logdate between '''|| pdatefrom ||''' and '''||pdateto ||''' ' || 'and logtime between ' ||
            ptimefrom||' and '||ptimeto; if ((P_SECTORID is not NULL) and (P_SECTORID > 0)) then LWHERE = :LWHERE ||
            ' and sectorid = '||:P_SECTORID; 
  script1 = 'select userid, agentid, skill, ' || 'Sum(Case when calltype = ''I'' then 1 else 0 end), ' || 
            'Sum(Case when calltype = ''I'' and talktime > 0 then 1 else 0 end), ' || 'Sum(Case when calltype = ''I'' 
            and talktime between 1 and 20 then 1 else 0 end), ' || 'Sum(Case when calltype = ''I'' and talktime = 0 
            and delaytime > 0 then 1 else 0 end), ' || 'Sum(Case when calltype = ''I'' then talktime + holdtime + 
            cnsholdtime else 0 end), ' || 'Sum(Case when calltype = ''O'' then 1 else 0 end), ' || 'Sum(Case when calltype = ''O'' 
            and talktime > 0 then 1 else 0 end), ' || 'Sum(Case when calltype = ''O'' and talktime between 1 and 20 then 1 
            else 0 end), ' || 'Sum(Case when calltype = ''O'' and talktime = 0 and delaytime > 0 then 1 else 0 end), 
            ' || 'Sum(Case when calltype = ''O'' then talktime + holdtime + cnsholdtime else 0 end) ' || 'from logpos ' || '
            where '||LWHERE|| ' group by userid, agentid, skill order by agentid, skill'; 
   for execute statement script1 into :userid, :agentid, :skill, :i_received, :i_answered, :i_short, :i_returned, 
              :tmp_i_talk, oreceived, oanswered, oshort, oreturned, :tmp_o_talk do begin select sum(interval_t), sum(idletime) 
   from logposint 
   where userid = :userid 
   and (logdate between pdatefrom and pdateto) 
   and (logtime between ptimefrom and ptimeto) 
   into :tmplogin, :tmpidle; 
   select * from sp_secsto_hhmmss(:tmplogin) into logintime; 
   select * from sp_secsto_hhmmss(:tmpidle) into idletime; 
   select * from sp_secsto_hhmmss(:tmp_i_talk) into i_talktime; 
   select * from sp_secsto_hhmmss(:tmp_o_talk) into o_talktime; 
   execute statement 'select user_fullname from users where userid = :userid' on external data source '192.168.x.x:sched' 
                      as user 'SYSDBA' password 'masterkey' 
     into :agentfullname; 
     suspend; 
   end 
 end
Responder Con Cita
  #7  
Antiguo 02-11-2014
Avatar de Young
Young Young is offline
Miembro
 
Registrado: abr 2006
Ubicación: San Felipe, Chile
Posts: 86
Poder: 18
Young Va por buen camino
Encontré lo siguiente:

sql-statement, user, password, role and <connect-string> are string
expressions. When given directly, i.e. as literal strings, they must
be enclosed in single-quote characters.

Me imagino entonces que debería lucir mas o menos así...

Código SQL [-]
execute statement 'select user_fullname from users where userid = :userid on external data source ''192.168.x.x:sched'' 
                      as user ''SYSDBA'' password ''masterkey'''

Me gusta más así:
Código SQL [-]
execute statement 'select user_fullname from users where userid = ' || :userid || 'on external data source ''192.168.x.x:sched'' 
                      as user ''SYSDBA'' password ''masterkey'''

Saludos.
Responder Con Cita
  #8  
Antiguo 03-11-2014
jars jars is offline
Miembro
 
Registrado: mar 2004
Posts: 279
Poder: 21
jars Va por buen camino
Young, en cualquiera de las dos formas compila y al ejecutar me da el error "Token unknown 'on'
Responder Con Cita
  #9  
Antiguo 03-11-2014
jars jars is offline
Miembro
 
Registrado: mar 2004
Posts: 279
Poder: 21
jars Va por buen camino
Encontre el problema, fue culpa mia, el campo por el que hacia la consulta habia sido cambiado por otro y yo ni enterado.
Ahora funciona bien.
Gracias por la ayuda que me dieron.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
DLL stdcall external marilinspi Varios 4 20-11-2013 18:26:08
Missing data provider or data packet mcalmanovici Providers 1 11-09-2007 06:55:15
External exception Besto Gráficos 0 15-11-2006 11:13:36
Los retos Micro-Open Souce: Delphi mamcx Varios 0 24-08-2006 19:48:35
external procedure arantzal .NET 3 16-12-2004 12:41:36


La franja horaria es GMT +2. Ahora son las 09:09:04.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi