Home   Artículos   Recursos   Foros   
Artíclos recientes publicados en Latindevelopers:
Visual C++: NSDoubleEdit: Un control para el manejo de números decimales en Visual C++.
Visual C++: Implementando una Calculadora en Visual C++
Visual C++: CCommandLine: Una clase para el uso de la linea de comando
Visual C++: Una clase para el manejo del Registro

Como executar sentencia sql

Arquitectura, Extending SQL, The Postgree Rule System, Intefacing, Trigers, ODBC, JDBC, C++...

Como executar sentencia sql

Notapor fvg1975 el Lun Dic 10, 2007 11:04 am

Buenos dias he creado un procedimeinto y dentro de el se va armando un query al final se almacena en una variable y dentro del procedure quiero ejecutar la sentencia pero no se que comando se usa. Intente con execute pero me pide otros parametros. Alguien puede ayudarme o conoce otro comando para poder hacer esto.
Gracias
Fernando

CREATE OR REPLACE FUNCTION proc_transactionlog_report2(pstartdate date, penddate date, porderby integer)
RETURNS SETOF character varying AS
$BODY$
/*
Author: Fernando Vasquez Gonzalez
Description: Rpt Transactions
Creation Date: 07/12/07
Modified:
*/
DECLARE
psql CHARACTER VARYING;
BEGIN

psql:= 'select a.customerid as "Customer",
a.classid as "Application",
b.carrierid as "Carrier",
a.technologyid as "Technology",
date(a.startdatetime) as "TransactionDate",
count(0) as "Cantidad_TX"
from tb_transactionlog a, tb_phonesubscriber b
where date(a.startdatetime)>='||$1||'
and date(a.startdatetime)<='||$2||'
and a.phonesubscriberid=b.phonesubscriberid
group by a.customerid,date(a.startdatetime),a.classid,b.carrierid,a.technologyid ';

IF $3=1
THEN
psql := psql || 'order by a.customerid';
End If;

IF $3=2
THEN
psql := psql || 'order by a.classid';
End If;

IF $3=3
THEN
psql := psql || 'order by b.carrierid';
End If;

IF $3=4
THEN
psql := psql || 'order by a.technologyid';
End If;
--psql := psql || ' order by a.customerid';
RAISE NOTICE '%',psql;

[b]EXECUTE psql; --- esta es la parte que no me funciona me sale error


End;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION proc_transactionlog_report2(pstartdate date, penddate date, porderby integer) OWNER TO db_billing;


El error es

ERROR: set-valued function called in context that cannot accept a set
SQL state: 0A000
fvg1975
Novato
Novato
 
Mensajes: 1
Registrado: Lun Dic 10, 2007 10:59 am

Re: Como executar sentencia sql

Notapor ivancp el Lun Dic 10, 2007 2:26 pm

Por que no intentas con la consulta PREPARE

http://www.postgresql.org/docs/8.1/stat ... epare.html
ivancp
Programador
Programador
 
Mensajes: 241
Registrado: Jue Sep 06, 2007 12:57 pm


Volver a PostgreSQL

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados