Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 30-04-2010
Ledian_Fdez Ledian_Fdez is offline
Miembro
 
Registrado: jun 2006
Ubicación: Ciudad Habana, Cuba
Posts: 242
Poder: 18
Ledian_Fdez Va por buen camino
Thumbs down Incorrect syntax near

Hola amigos de este foro:
Tengo 2 tablas (Existencia y Salida)

Intento hacer un procedimiento almacenado donde se le de salida a un producto existente y cantidad.


Este es el código:
Código SQL [-]
 create procedure Nueva_BajaIns

@CodSAF varchar(4),
@CodIns varchar(5),
@Cant int,
@Motivo char(2),
@Fecha datetime,
@Observ varchar(50)

AS

declare @errorvar int
set @errorvar = 0

declare @Total int
set @Total = 0

begin transaction
 /* si el producto existe */
 if exists(select * from Existencia where SAF=@CodSAF and INS=@CodIns)  
   begin
     /* guardo en @Total la disponibilidad */
    @Total = select Cant from Existencia where SAF=@CodSAF and INS=@CodIns
    /* si la disponibilidad del producto satisface */
    if(@Total >= @Cant)
    begin
     /* inserto en salida */
     insert into Salidas (CodSAF, CodIns, Cant, Motivo, Fecha, Observ)
     values (@CodSAF, @CodIns, @Cant, @Motivo, @Fecha, @Observ)
     set @errorvar = @errorvar + @@ERROR   
     
     /* Si aun queda disponibilidad    */
     if(@Total > @Cant)
       begin 
  update Existencia
        set Cant = Cant - @Cant  -- realizo la resta para saber disponibilidad una vez hecha la salida
        where SAF=@CodSAF and INS=@CodIns
        set @errorvar = @errorvar + @@ERROR
       end
     else /* si la disponibilidad se queda en cero elimino el producto de existencia */
       begin
  delete from Existencia
  where SAF=@CodSAF and INS=@CodIns
  set @errorvar = @errorvar + @@ERROR
       end
    end
  
 if (@errorvar = 0)
   commit transaction
 else
   rollback transaction

Me da este error:
Cita:
Server: Msg 170, Level 15, State 1, Procedure Nueva_BajaIns, Line 26
Line 26: Incorrect syntax near '@Total'.

En espera de su ayuda y muchas gracias de antemano.

Salu2,
Ledian.

Última edición por Ledian_Fdez fecha: 30-04-2010 a las 22:56:40.
Responder Con Cita
 



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
Incorrect values within SQLDA structure fedelinardi SQL 5 01-02-2018 03:52:07
Como crear un "Cryptographic Message Syntax" en Delphi? old_martinez Varios 3 09-12-2016 15:41:59
Incorrect string value Willo MySQL 0 07-04-2010 19:45:55
error (incorrect token followed by ":") en query voldemmor Conexión con bases de datos 4 16-04-2008 18:27:00
Truncated incorrect Double value: 'Airport' richy08 MySQL 5 10-10-2007 17:11:22


La franja horaria es GMT +2. Ahora son las 00:37:33.


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