O.T. ADS - Consulta SQL (SOLUCIONADO)

Post Reply
User avatar
MarioG
Posts: 1356
Joined: Fri Oct 14, 2005 1:28 pm
Location: Resistencia - Chaco - AR

O.T. ADS - Consulta SQL (SOLUCIONADO)

Post by MarioG »

Gente:
Segun el pdf de ayuda que tengo, para acutalizar un campo, con datos de otro campo se puede hacer de la siguiente manera:
  • UPDATE stock SET stock.quantity = t.quantity
    FROM stock INNER JOIN stock t ON stock.id = t.id
    WHERE t.state = 1
Para mi caso lo hago de la siguiente manera (desde el ARC)
  • UPDATE BDSGC03 SET BDSGC03.FCABFA14= SUM(D.FDETFA06*(D.FDETFA08-D.FDETFA07))
    FROM BDSGC03 INNER JOIN BDSGC04 AS D ON BDSGC03.FDOCINT1=D.FDOCINT1
    WHERE BDSGC03.FCABFA14=0
Y me devuelve el siguiente error:
ERROR IN SCRIPT: poQuery: Error 7200: AQE Error: State = 42000; NativeError = 2117; [iAnywhere Solutions][Advantage SQL Engine]Unexpected token: SELECT -- Expecting
semicolon. -- Location of error in the SQL statement is: 754 (line: 16 column: 1)

Cual sería la forma correcta?
Last edited by MarioG on Mon Jun 15, 2015 1:54 pm, edited 1 time in total.
Resistencia - "Ciudad de las Esculturas"
Chaco - Argentina
nnicanor
Posts: 296
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: O.T. ADS - Consulta SQL

Post by nnicanor »

Revisa el codigo, el AS te esta causando el error


UPDATE BDSGC03 SET BDSGC03.FCABFA14= SUM(D.FDETFA06*(D.FDETFA08-D.FDETFA07))
FROM BDSGC03 INNER JOIN BDSGC04 AS D ON BDSGC03.FDOCINT1=D.FDOCINT1
WHERE BDSGC03.FCABFA14=0

Forma correcta:

Code: Select all


UPDATE BDSGC03 SET BDSGC03.FCABFA14= SUM(D.FDETFA06*(D.FDETFA08-D.FDETFA07))
FROM BDSGC03 INNER JOIN BDSGC04  D ON BDSGC03.FDOCINT1=D.FDOCINT1 
WHERE BDSGC03.FCABFA14=0

 
Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
User avatar
MarioG
Posts: 1356
Joined: Fri Oct 14, 2005 1:28 pm
Location: Resistencia - Chaco - AR

Re: O.T. ADS - Consulta SQL

Post by MarioG »

Nicanor, gracias por responder
Elimine al Alias
  • UPDATE BDSGC03 SET BDSGC03.FCABFA14= SUM(BDSGC04.FDETFA06*(BDSGC04.FDETFA08-BDSGC04.FDETFA07))
    FROM BDSGC03 INNER JOIN BDSGC04 ON BDSGC03.FDOCINT1=BDSGC04.FDOCINT1
    WHERE BDSGC03.FCABFA14=0
No le gusta, repite el error:
  • ERROR IN SCRIPT: poQuery: Error 7200: AQE Error: State = S0000; NativeError = 2149; [iAnywhere Solutions][Advantage SQL Engine]Aggregate function not allowed in this
    context: Not a SELECT statement.
Resistencia - "Ciudad de las Esculturas"
Chaco - Argentina
User avatar
MarioG
Posts: 1356
Joined: Fri Oct 14, 2005 1:28 pm
Location: Resistencia - Chaco - AR

Re: O.T. ADS - Consulta SQL

Post by MarioG »

Nicanor;
Lo que no le gusta es el SUM()!
  • UPDATE BDSGC03 SET BDSGC03.FCABFA14= BDSGC04.FDETFA06*(BDSGC04.FDETFA08-BDSGC04.FDETFA07)
    FROM BDSGC03 INNER JOIN BDSGC04 ON BDSGC03.FDOCINT1=BDSGC04.FDOCINT1
    WHERE BDSGC03.FCABFA14=0
Asi funciona.
Debería hacer el calculo en una variable?, como? (mientras sigo leyendo)
Resistencia - "Ciudad de las Esculturas"
Chaco - Argentina
nnicanor
Posts: 296
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: O.T. ADS - Consulta SQL

Post by nnicanor »

El SUM solamente se puede usar con GROUP BY

Slds,
Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
User avatar
joseluisysturiz
Posts: 2024
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: O.T. ADS - Consulta SQL

Post by joseluisysturiz »

MarioG wrote:Nicanor;
Lo que no le gusta es el SUM()!
  • UPDATE BDSGC03 SET BDSGC03.FCABFA14= BDSGC04.FDETFA06*(BDSGC04.FDETFA08-BDSGC04.FDETFA07)
    FROM BDSGC03 INNER JOIN BDSGC04 ON BDSGC03.FDOCINT1=BDSGC04.FDOCINT1
    WHERE BDSGC03.FCABFA14=0
Asi funciona.
Debería hacer el calculo en una variable?, como? (mientras sigo leyendo)
Prueba hacer la operacion con un administrador como navicar, sqlyoj o cualquier otro, ya que he usado el SUM parecido como lo haces y no he tenido problemas, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
Posts: 2024
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: O.T. ADS - Consulta SQL

Post by joseluisysturiz »

MarioG wrote:Nicanor;
Lo que no le gusta es el SUM()!
  • UPDATE BDSGC03 SET BDSGC03.FCABFA14= BDSGC04.FDETFA06*(BDSGC04.FDETFA08-BDSGC04.FDETFA07)
    FROM BDSGC03 INNER JOIN BDSGC04 ON BDSGC03.FDOCINT1=BDSGC04.FDOCINT1
    WHERE BDSGC03.FCABFA14=0
Asi funciona.
Debería hacer el calculo en una variable?, como? (mientras sigo leyendo)
Forma correcta y ya probado....saludos... :shock:

UPDATE `facturas_copy` SET sumatoria=(SELECT SUM(mtopagado*2))
where mtopagado>0;

http://nideaderedes.urlansoft.com/2008/ ... tra-tabla/
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
MarioG
Posts: 1356
Joined: Fri Oct 14, 2005 1:28 pm
Location: Resistencia - Chaco - AR

Re: O.T. ADS - Consulta SQL

Post by MarioG »

Bien respondo antes de probarlo.
AsÍ debe ser porque en el error hacia referencia al SELECT!

gracias!!
Resistencia - "Ciudad de las Esculturas"
Chaco - Argentina
User avatar
joseluisysturiz
Posts: 2024
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: O.T. ADS - Consulta SQL

Post by joseluisysturiz »

MarioG wrote:Bien respondo antes de probarlo.
AsÍ debe ser porque en el error hacia referencia al SELECT!

gracias!!
Por lo visto si quieres usar funciones..se debe usar el SELECT como si fuese una sub-consulta, sino, entonces puedes aplicar la sumatoria como lo hicistes sin el SUM(), mas que todo uso el SUM para hacer calculo de varias columnas y crear un campo virtual, espero te sirva, ambas formas ya las probe y funcionaron, avisa como te va cuando lo pruebes, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
MarioG
Posts: 1356
Joined: Fri Oct 14, 2005 1:28 pm
Location: Resistencia - Chaco - AR

Re: O.T. ADS - Consulta SQL

Post by MarioG »

Nicanor, Jose Luis; muchas gracias!
Realmente si no hubiese contado con vuestro interes por ayudar, no hubiese podido llegar a la solución.
bueno, no es ninguna novedad en este foro donde todos colegas ofrecen su tiempo para ayudar al resto.

José Luis, espectacular el enlace, presenta exactamente lo que planteo aquí, y lo tomo como lugar de consulta, ya que seguramente obtendré muy buena info.
Y seguramente a muchos les será muy útil
Resistencia - "Ciudad de las Esculturas"
Chaco - Argentina
User avatar
joseluisysturiz
Posts: 2024
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela
Contact:

Re: O.T. ADS - Consulta SQL

Post by joseluisysturiz »

MarioG wrote:Nicanor, Jose Luis; muchas gracias!
Realmente si no hubiese contado con vuestro interes por ayudar, no hubiese podido llegar a la solución.
bueno, no es ninguna novedad en este foro donde todos colegas ofrecen su tiempo para ayudar al resto.

José Luis, espectacular el enlace, presenta exactamente lo que planteo aquí, y lo tomo como lugar de consulta, ya que seguramente obtendré muy buena info.
Y seguramente a muchos les será muy útil
A la orden siempre y cuando se pueda, una ayuda a alguien del foro, es un aumento al diccionario de informacion para otros...saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
Post Reply