Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > MS SQL Server
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 03-02-2009
Tauro78 Tauro78 is offline
Miembro
 
Registrado: sep 2006
Posts: 88
Poder: 18
Tauro78 Va por buen camino
Procedimiento almacenado en SQL Server

hola, tengo un SP que deberia chequear si existe el nombre de una empresa
antes de darla de alta, entonces si ya existe una empresa con ese nombre
lo guarda en la variable @nombre, luego pregunto si la variable me devuelve un valor no nulo entonces ya existe una empresa con ese nombre, pero el SP me da el siguiente error:

Mens 208, Nivel 16, Estado 6, Procedimiento SP_EXISTE_EMPRESA, Línea 17
Invalid object name 'dbo.SP_EXISTE_EMPRESA'.

estoy usando Microsoft SQL Server Managment Studio Express, desde ya
muchas gracias.

ALTERPROCEDURE [dbo].[SP_EXISTE_EMPRESA]
-- Add the parameters for the stored procedure here
@SP_NOMBRE NVARCHAR(50),
@NOMBRE
NVARCHAR(50) OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT EMPRESAS.NOMBRE FROM EMPRESAS
WHERE EMPRESAS.NOMBRE = @SP_NOMBRE
RETURN @NOMBRE
-- Insert statements for procedure here
END

Responder Con Cita
  #2  
Antiguo 03-02-2009
luisgutierrezb luisgutierrezb is offline
Miembro
 
Registrado: oct 2005
Ubicación: México
Posts: 925
Poder: 19
luisgutierrezb Va por buen camino
pusiste todo el codigo del SP?? el error menciona una linea 17 y todo lo que pusiste son 14 lineas, ya pudiste correr 1 vez el procedimiento? esto porque usas el Alter pero si no existe no lo modifica, necesitas primero el create procedure y despues el Alter
Responder Con Cita
  #3  
Antiguo 03-02-2009
Tauro78 Tauro78 is offline
Miembro
 
Registrado: sep 2006
Posts: 88
Poder: 18
Tauro78 Va por buen camino
Este es el codigo completo del SP, gracias

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATEPROCEDURE [dbo].[SP_EXISTE_EMPRESA]
-- Add the parameters for the stored procedure here
@SP_NOMBRE NVARCHAR(50),
@NOMBRE
NVARCHAR(50) OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT EMPRESAS.NOMBRE FROM EMPRESAS
WHERE EMPRESAS.NOMBRE = @SP_NOMBRE
RETURN @NOMBRE
-- Insert statements for procedure here
END
GO
Responder Con Cita
  #4  
Antiguo 04-02-2009
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.281
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Pues yo lo he probado y funciona perfectamente, salvo por una cosa:
* En el CREATEPROCEDURE te falta un espacio entre ambas palabras (supongo que es error de transcripción)

Supongo además que cuando ya está creado, utilizas ALTER PROCEDURE en lugar de CREATE PROCEDURE para modificarlo. Por lo demás lo dicho, a mi me funciona bien.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #5  
Antiguo 04-02-2009
Avatar de ContraVeneno
ContraVeneno ContraVeneno is offline
Miembro
 
Registrado: may 2005
Ubicación: Torreón, México
Posts: 4.738
Poder: 23
ContraVeneno Va por buen camino
Salvo el espacio en "CREATE PROCEDURE", a mi también me funcionó bien.
__________________

Responder Con Cita
  #6  
Antiguo 04-02-2009
Avatar de jcarteagaf
[jcarteagaf] jcarteagaf is offline
Miembro Premium
 
Registrado: abr 2006
Ubicación: La Paz, Bolivia
Posts: 651
Poder: 19
jcarteagaf Va por buen camino
Si el procedimiento no existe deberias usar CREATE PROCEDURE en vez de ALTER PROCEDURE y ademas creo que deberias asignar el valor a tu variable de salida:


Código SQL [-]
CREATE PROCEDURE [dbo][SP_EXISTE_EMPRESA] 
-- Add the parameters for the stored procedure here
@SP_NOMBRE NVARCHAR(50), 
@NOMBRE NVARCHAR(50]) OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
  SET NOCOUNT ON;
  SELECT @NOMBRE = EMPRESAS.NOMBRE FROM EMPRESAS 
  WHERE EMPRESAS.NOMBRE = @SP_NOMBRE
  RETURN @NOMBRE
 
END

Saludos

Última edición por jcarteagaf fecha: 04-02-2009 a las 22:00:30.
Responder Con Cita
  #7  
Antiguo 04-02-2009
mierda mierda is offline
Miembro
 
Registrado: may 2006
Posts: 129
Poder: 18
mierda Va por buen camino
Pa mi q te falta esto

SELECT @nombre = EMPRESAS.NOMBRE FROM EMPRESAS
WHERE EMPRESAS.NOMBRE = @SP_NOMBRE

Un saludo

Responder Con Cita
  #8  
Antiguo 06-02-2009
Avatar de poliburro
[poliburro] poliburro is offline
Miembro Premium
 
Registrado: ago 2004
Ubicación: México D.F
Posts: 3.068
Poder: 23
poliburro Va por buen camino
Ese error indica que estás tratando de modificar un SP que no existe,
Arega el siguiente encabezado:

Código SQL [-]
 
IF EXISTS (SELECT name 
    FROM   sysobjects 
    WHERE  name = N'SP_EXISTE_EMPRESA' 
    AND    type = 'P')
    DROP PROCEDURE SP_EXISTE_EMPRESA
GO
 
CREATE PROCEDURE SP_EXISTE_EMPRESA
.....


Saludos.
__________________
Conoce mi blog http://www.edgartec.com
Responder Con Cita
Respuesta



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
procedimiento almacenado sargento elias Firebird e Interbase 1 14-04-2008 13:04:35
Procedimiento almacenado efelix MS SQL Server 7 21-11-2007 17:53:00
ejecutar Procedimiento almacenado en SQL Server, Intraweb. Roilo Internet 9 25-07-2007 18:01:32
Procedimiento Almacenado scooterjgm Conexión con bases de datos 5 18-01-2005 18:21:32
Procedimiento Almacenado Ulises Providers 3 30-01-2004 18:14:58


La franja horaria es GMT +2. Ahora son las 21:08:20.


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