SQLExpress - Xb2.NET     ot4xb  
xfree.public
Consulta Postgree Sql
Thread Starter: Jose Valle Started: 6/2/2008 3:33 PM UTC
Replies: 11
Consulta Postgree Sql
Hola:  Estoy empezando con PostgreSql.  Pgadmin3 me ha ayudado mucho a entender sql. Tengo la impresión de que además de fiabilidad vamos a ganar claridad en nuestras aplicaciones.

En mi aplicacion contable, en el fichero de asientos, tengo las columnas 'cuenta','debehaber','importe'

para calcular un balance de sumas y saldos a una fecha puedo usar (casi)

SELECT cuenta, sum(importe) AS saldo  FROM apuntes WHERE fecha <= '" + DtoC(mFecha) +"' GROUP BY cuenta ORDER BY cuenta ASC")

pero tengo un problema. en vez de sum(importe) querria poner sum(iif(debehaber="D",importe,-importe))

¿Sabéis como se puede hacer eso?

por cierto que estoy sorprendidisimo con la velocidad que devuelve resultados, con 1530 cuentas y 75640 apuntes me tarda 1 segundo, lo mismo para el saldo de una cuenta a una fecha que de todas las cuentas. Con dbf me tardaba 6 segundos en local y 200 segundos en 2003 server.

Con esto doy por bueno el consejo de no guardar datos acumulados (saldos de cuenta, stocks de artículos, etc)


Hasta pronto

Jose Valle
Re: Consulta Postgree Sql
Estimado Jose Valle

Te comento yo estoy apenas en la parte de los browses, e igual que tu
veo muy bien los resultados usando ODBC con SQLExpress++.

No me se la respuesta, pero igual voy a investigar.
Lo que he visto y tengo que analizar es que usando SQLExpress++ los campos integer me los devuelve tipo "Caracter", aun no he puesto el ejemplo en el foro de Boriz, pero en cuanto tenga un test, lo pongo.

Ahora has visto las funciones q trae integradas PostgreSQL ?
A lo mejor ahi hay para hacer condiciones...

Saludos
Osvaldo Ramirez


wrote:
Hola:  Estoy empezando con PostgreSql.  Pgadmin3 me ha ayudado mucho a entender sql. Tengo la impresión de que además de fiabilidad vamos a ganar claridad en nuestras aplicaciones.
En mi aplicacion contable, en el fichero de asientos, tengo las columnas 'cuenta','debehaber','importe'
para calcular un balance de sumas y saldos a una fecha puedo usar (casi)
SELECT cuenta, sum(importe) AS saldo  FROM apuntes WHERE fecha <= '" + DtoC(mFecha) +"' GROUP BY cuenta ORDER BY cuenta ASC")
pero tengo un problema. en vez de sum(importe) querria poner sum(iif(debehaber="D",importe,-importe))
¿Sabéis como se puede hacer eso?
por cierto que estoy sorprendidisimo con la velocidad que devuelve resultados, con 1530 cuentas y 75640 apuntes me tarda 1 segundo, lo mismo para el saldo de una cuenta a una fecha que de todas las cuentas. Con dbf me tardaba 6 segundos en local y 200 segundos en 2003 server.
Con esto doy por bueno el consejo de no guardar datos acumulados (saldos de cuenta, stocks de artículos, etc)

Hasta pronto
Jose Valle

Re: Consulta Postgree Sql
Estimado Jose Valle

Tienes FastReport for Xbase++ ?
Si, si, has probado el uso de select y ver reportes en este ?

Saludos
Osvaldo Ramirez

 wrote:
Hola:  Estoy empezando con PostgreSql.  Pgadmin3 me ha ayudado mucho a entender sql. Tengo la impresión de que además de fiabilidad vamos a ganar claridad en nuestras aplicaciones.
En mi aplicacion contable, en el fichero de asientos, tengo las columnas 'cuenta','debehaber','importe'
para calcular un balance de sumas y saldos a una fecha puedo usar (casi)
SELECT cuenta, sum(importe) AS saldo  FROM apuntes WHERE fecha <= '" + DtoC(mFecha) +"' GROUP BY cuenta ORDER BY cuenta ASC")
pero tengo un problema. en vez de sum(importe) querria poner sum(iif(debehaber="D",importe,-importe))
¿Sabéis como se puede hacer eso?
por cierto que estoy sorprendidisimo con la velocidad que devuelve resultados, con 1530 cuentas y 75640 apuntes me tarda 1 segundo, lo mismo para el saldo de una cuenta a una fecha que de todas las cuentas. Con dbf me tardaba 6 segundos en local y 200 segundos en 2003 server.
Con esto doy por bueno el consejo de no guardar datos acumulados (saldos de cuenta, stocks de artículos, etc)

Hasta pronto
Jose Valle

Re: Consulta Postgree Sql
Hi all,

just one question: are news groups in news.xbwin.com
"international" or "spanish" speaking/writing?
It looks, here are(and will be step-by-step)
already many usefull informations,
but it is very time-consuming for me
translate almost message to english
or to my national language...
Pablo Botella is in "dual" mode, but many others not...

      Zdeno
Re: Consulta Postgree Sql
Dear Zdeno Bielik

I am very sorry,
I forgot to try, at least translate the question .and. answer.

We dont want to exclude people that write or speak english, but
some times, when some of us, ask in spanish, answer in spanish.


But, follow the topic.

Jose ask :

Is there a way to do this :

SELECT cuenta, sum(iif(debehaber="D",importe,-importe)) AS saldo  FROM apuntes WHERE fecha <= '" + DtoC(mFecha) +"' GROUP BY cuenta ORDER BY cuenta ASC")

And I said, that I dont know, but we need to investigate if PostgreSQL has a function like "iif".

....

And my question was if he has a Fast Report if yes, if he has been testing FastReport for Xbase++ using Postgresql.

Again, I am sorry, and will kept in mind to try to traslate or response   in "dual" mode.

Best Regards
Osvaldo Ramirez




 - ACE System wrote:
Hi all,
just one question: are news groups in news.xbwin.com
"international" or "spanish" speaking/writing?
It looks, here are(and will be step-by-step)
already many usefull informations,
but it is very time-consuming for me
translate almost message to english
or to my national language...
Pablo Botella is in "dual" mode, but many others not...
      Zdeno
Re: Consulta Postgree Sql
Hi,

just one question: are news groups in news.xbwin.com
"international" or "spanish" speaking/writing?
Good question.

I was hosting initially in this NS the groups ot4xb,sqlexpress,xb2net from years was international and everybody writes in english.

When Osvaldo and Hector was proposed me to include also the xfree.* groups in my server, I was think will be usefull to have a readonly secion of resources and of course in xfree.resources all the content MUST be in ENGLISH in the benefit of the entire Xbase++ comunity

Also will be nice that content in xfree.public will be in english, but the english language is hard to some spanish speakers, and also the original xfree groups in yahoo was in spanish so I think think we can tolerate some spanish incursions here, Osvaldo, Jose Luis and me will try to translate to english at least the most relevant messages, and in the worst case mature projects will be published in english in xfree.resources

Regards,
Pablo Botella
Re: Consulta Postgree Sql
I will also write in English ( or something like that)



"Osvaldo Ramirez" <ramirezosvaldo@yahoo.com> escribió en el mensaje de noticias news:5dfbd283$5cb0a00f$a70b@news.xbwin.com...
Dear Zdeno Bielik

I am very sorry,
I forgot to try, at least translate the question .and. answer.

We dont want to exclude people that write or speak english, but
some times, when some of us, ask in spanish, answer in spanish.


But, follow the topic.

Jose ask :

Is there a way to do this :

SELECT cuenta, sum(iif(debehaber="D",importe,-importe)) AS saldo  FROM apuntes WHERE fecha <= '" + DtoC(mFecha) +"' GROUP BY cuenta ORDER BY cuenta ASC")

And I said, that I dont know, but we need to investigate if PostgreSQL has a function like "iif".

....

And my question was if he has a Fast Report if yes, if he has been testing FastReport for Xbase++ using Postgresql.

Again, I am sorry, and will kept in mind to try to traslate or response in "dual" mode.

Best Regards
Osvaldo Ramirez




- ACE System wrote:
> Hi all,
>
> just one question: are news groups in news.xbwin.com
> "international" or "spanish" speaking/writing?
> It looks, here are(and will be step-by-step)
> already many usefull informations,
> but it is very time-consuming for me
> translate almost message to english
> or to my national language...
> Pablo Botella is in "dual" mode, but many others not...
>
>        Zdeno
>
Re: Consulta Postgree Sql
Jose Valle escribió:
Hola:  Estoy empezando con PostgreSql.  Pgadmin3 me ha ayudado mucho a entender sql. Tengo la impresión de que además de fiabilidad vamos a ganar claridad en nuestras aplicaciones.
En mi aplicacion contable, en el fichero de asientos, tengo las columnas 'cuenta','debehaber','importe'
para calcular un balance de sumas y saldos a una fecha puedo usar (casi)
SELECT cuenta, sum(importe) AS saldo  FROM apuntes WHERE fecha <= '" + DtoC(mFecha) +"' GROUP BY cuenta ORDER BY cuenta ASC")
pero tengo un problema. en vez de sum(importe) querria poner sum(iif(debehaber="D",importe,-importe))
¿Sabéis como se puede hacer eso?
por cierto que estoy sorprendidisimo con la velocidad que devuelve resultados, con 1530 cuentas y 75640 apuntes me tarda 1 segundo, lo mismo para el saldo de una cuenta a una fecha que de todas las cuentas. Con dbf me tardaba 6 segundos en local y 200 segundos en 2003 server.
Con esto doy por bueno el consejo de no guardar datos acumulados (saldos de cuenta, stocks de artículos, etc)

Hasta pronto
Jose Valle



Jose:

Tal vez esto te pueda ayudar...
Maybe this can help you...

http://www.postgresql.org/docs/8.3/interactive/functions-conditional.html#AEN14417


Saludos
Angel
Condicional expresions in sql
Tal vez esto te pueda ayudar...
Maybe this can help you...

http://www.postgresql.org/docs/8.3/interactive/functions-conditional.html#AEN14417

Thanks very much Angel. It works perfect

In pgadmin:

SELECT cuenta, sum(CASE WHEN debehaber='D' THEN importe ELSE -importe END) FROM apuntes group by cuenta order by cuenta ;

in sqlexpress

oCursor := oConn:Cursor("SELECT cuenta, sum( CASE WHEN debehaber='D' THEN importe ELSE -importe END) AS saldo  FROM apuntes WHERE fecha <= '" + DtoC(mFecha) +"' GROUP BY cuenta ORDER BY cuenta ASC")

But It is very, very fast.

Another question: will you move to sql?

Regards
Re: Consulta Postgree Sql
Hi,

Thanks for the translations. English is also not my mature language, but
Spanish is unreadable for me.

Regards,
Chris Andries



"Pablo Botella" <pbn_NOSPAM_@pablob.com> wrote in message
news:7e838548$2b147270$a714@news.xbwin.com...
Hi,

just one question: are news groups in news.xbwin.com
"international" or "spanish" speaking/writing?
Good question.

I was hosting initially in this NS the groups ot4xb,sqlexpress,xb2net from
years was international and everybody writes in english.

When Osvaldo and Hector was proposed me to include also the xfree.* groups
in my server, I was think will be usefull to have a readonly secion of
resources and of course in xfree.resources all the content MUST be in
ENGLISH in the benefit of the entire Xbase++ comunity

Also will be nice that content in xfree.public will be in english, but the
english language is hard to some spanish speakers, and also the original
xfree groups in yahoo was in spanish so I think think we can tolerate some
spanish incursions here, Osvaldo, Jose Luis and me will try to translate to
english at least the most relevant messages, and in the worst case mature
projects will be published in english in xfree.resources

Regards,
Pablo Botella
Re: Condicional expresions in sql
I'm glad it worked =)
Excuse me but I was 2 days working out of city.
Yes I'm in the process on moving all business logic to the database via VIEWS, STORED PROCEDURES and learning along the way.

Jose Valle escribió:
> Tal vez esto te pueda ayudar...
> Maybe this can help you...
>
> http://www.postgresql.org/docs/8.3/interactive/functions-conditional.html#AEN14417 >
Thanks very much Angel. It works perfect
In pgadmin:
SELECT cuenta, sum(CASE WHEN debehaber='D' THEN importe ELSE -importe END) FROM apuntes group by cuenta order by cuenta ;
in sqlexpress
oCursor := oConn:Cursor("SELECT cuenta, sum( CASE WHEN debehaber='D' THEN importe ELSE -importe END) AS saldo  FROM apuntes WHERE fecha <= '" + DtoC(mFecha) +"' GROUP BY cuenta ORDER BY cuenta ASC")
But It is very, very fast.
Another question: will you move to sql?
Regards
Re: Consulta Postgree Sql
Hello: This works good for me.

SELECT sum( CASE WHEN DebeHaber='D' THEN Importe END ) AS SumaDebe,sum( CASE WHEN DebeHaber='H' THEN Importe END ) AS SumaHaber FROM apuntes WHERE cuenta = '4300000'