Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   error "Subquery returned more than 1 value" (https://www.clubdelphi.com/foros/showthread.php?t=34561)

lynu 14-08-2006 14:12:19

error "Subquery returned more than 1 value"
 
Código SQL [-]
update tbl_articulo 

set
    costo = (select tbl_detalle_nota_entrada.costo from tbl_detalle_nota_entrada
         where tbl_articulo.id_articulo = (select tbl_detalle_nota_entrada.id_producto from tbl_detalle_nota_entrada 
                                       where tbl_detalle_nota_entrada.id_nota_entrada = @id_nota_entrada )
         and tbl_detalle_nota_entrada.id_nota_entrada = @id_nota_entrada),

    almacen_1 = almacen_1 + (select tbl_detalle_nota_entrada.cantidad from tbl_detalle_nota_entrada  
                 where tbl_articulo.id_articulo = (select tbl_detalle_nota_entrada.id_producto from tbl_detalle_nota_entrada 
                                       where tbl_detalle_nota_entrada.id_nota_entrada = @id_nota_entrada )
                 and tbl_detalle_nota_entrada.id_nota_entrada = @id_nota_entrada),

    almacen_1_fecha = (select tbl_nota_entrada.fecha from tbl_nota_entrada
               where tbl_nota_entrada.id_nota_entrada = @id_nota_entrada)
    

where    tbl_articulo.id_articulo = (select tbl_detalle_nota_entrada.id_producto from tbl_detalle_nota_entrada 
                                       where tbl_detalle_nota_entrada.id_nota_entrada = @id_nota_entrada)


bueno este largo Stored Preocedure :d resulta si solo le envio 1 elemento, pero si existe mas de 1 me da un error tal como "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression." me gustaria saber si alguien sabe como resolver este problema. cualquier duda del codigo pregunten :D


Sinaloense 14-08-2006 16:16:25

Serciorate que el subquery si regrese un solo valor:

Código SQL [-]
costo = (select  tbl_detalle_nota_entrada.costo from tbl_detalle_nota_entrada
         where tbl_articulo.id_articulo = (select first 1 tbl_detalle_nota_entrada.id_producto from tbl_detalle_nota_entrada 
                                       where tbl_detalle_nota_entrada.id_nota_entrada = @id_nota_entrada )
         and tbl_detalle_nota_entrada.id_nota_entrada = @id_nota_entrada),


La franja horaria es GMT +2. Ahora son las 11:11:12.

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