Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

Estas en el tema de Problemas Con Parametros En El Stored Procedure!!!!!!!!!!! en el foro de SQL Server en Foros del Web. hola espero que alguien me pueda ayudar con esto: Resulta que estoy haciendo un stored en donde declaro lo siguiente: @accion int, y las acciones ...
  #1 (permalink)  
Antiguo 24/04/2008, 13:56
 
Fecha de Ingreso: abril-2008
Ubicación: MEXICO D.F.
Mensajes: 22
Antigüedad: 16 años
Puntos: 0
Exclamación Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

hola espero que alguien me pueda ayudar con esto:

Resulta que estoy haciendo un stored en donde declaro lo siguiente:

@accion int,

y las acciones que hace dentro del stored son estas 2:
----------------------------------------------------------------------------
if @accion=1
Begin
delete from TempRServiciosProgramados
where UsuarioActivo=@UsuarioActivo
end
-----------------------------------------------------------------------------
if @accion=2
begin
Select A.Estatus
from AsignacionServicio as AB,Actividad A
where AB.IDUsuario=@IDUsuario
and AB.IDSoporteServicio=@NSoporte
and AB.IDSoporteServicio=A.IDSoporteServicio
and AB.IDAsignacionServicio=A.IDAsignacionServicio
and AB.IDServicio is null
order by A.Estatus
end
--------------------------------------------------------------------------------

EL PROBLEMA ES QUE SI ME GUARDA EL STORED BIEN PERO A LA HORA DE MANDARLO LLAMAR ME MARCA ESTE ERROR:

Servidor: mensaje 201, nivel 16, estado 4, procedimiento sp_RServiciosProgramados, línea 0
El procedimiento 'sp_RServiciosProgramados' precisa el parámetro '@accion', que no se ha especificado.

Porfavor si alguien sabe AYUDENMEEEEEEE!!!!
  #2 (permalink)  
Antiguo 24/04/2008, 14:09
Avatar de flaviovich  
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 8 meses
Puntos: 39
Re: Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

Simplemente no le has pasado ese parametro.
Código:
EXEC sp_RServiciosProgramados '@accion=1'
Seria mejor que muestres tu SP.
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.
  #3 (permalink)  
Antiguo 24/04/2008, 14:16
 
Fecha de Ingreso: abril-2008
Ubicación: MEXICO D.F.
Mensajes: 22
Antigüedad: 16 años
Puntos: 0
Exclamación Re: Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

ESTE ES TODO EL STORED ESPERO LE ENTIENDAS Y ME PUEDAS AYUDAR
GRACIAS alegna*


CREATE proc sp_RServiciosProgramados_mod
(
@UsuarioActivo varchar(10) = null,
@NUsuario int = null,
@CURP varchar(25) = null,
@NSoporte int = null,
@IDCategoria smallint = null,
@IDEspecialidad smallint = null,
@IDFederacion smallint = null,
@IDServicio smallint = null,
@IDSubServicio smallint = null,
@FechaInicial datetime = null,
@FechaFinal datetime = null,
@IDInstalacion smallint = null,
@accion int,
@IDUsuario int =null
)
as

declare @strSQL varchar(5500)
declare @FechaHoy datetime
select @FechaHoy= getdate()


if @accion=1
Begin
delete from TempRServiciosProgramados
where UsuarioActivo=@UsuarioActivo


SET @strSQL = ''

SET @strSQL = @strSQL + ' INSERT INTO TempRServiciosProgramados (Instalacion,Federacion,FechaInicio,FechaFin,Servi cio,'
SET @strSQL = @strSQL + ' SubServicio,Nombre,ApellidoPaterno,ApellidoMaterno ,IDSoporteServicio,NumeroAtleta,'
SET @strSQL = @strSQL +' CURP,IDCategoria,IDEspecialidad,IDFederacion,IDSer vicio,IDSubservicio,'
SET @strSQL = @strSQL + ' UsuarioActivo, IDInstalacion, Habitacion,Sexo,IDUsuario)'

SET @strSQL = @strSQL + 'SELECT I.Descripcion,F.Descripcion,convert(varchar(2),dat epart(mm,RAD.Fecha)) +'
SET @strSQL = @strSQL + 'convert(varchar(2),datepart(dd,RAD.Fecha)) + convert(varchar(4),datepart(yyyy,RAD.Fecha)),'
SET @strSQL = @strSQL + 'convert(varchar(2),datepart(hh,RAD.Hora))+ convert(varchar(2),datepart(mi,RAD.Hora)),'

SET @strSQL = @strSQL + 'S.Descripcion,SS.Descripcion,U.Nombre,U.ApellidoP aterno,
U.ApellidoMaterno,SP.IDSoporteServicio,'
SET @strSQL = @strSQL + ' U.NumeroAtleta,U.CURP,U.IDCategoria,U.IDEspecialid ad,SP.IDFederacion, ASE.IDServicio,ASE.IDSubservicio,"'+@UsuarioActivo +'",U.IdEstatus, ASE.IDInstalacion,ASE.NumeroHabitacion,U.Sexo,U.ID Usuario'

SET @strSQL = @strSQL + 'from'
SET @strSQL = @strSQL + ' AsignacionServicio as ASE,Federacion as F,Servicio as S,Subservicio as SS,Instalacion as I, SoporteServicio as SP,Usuario as U,'

SET @strSQL = @strSQL + 'Where'

SET @strSQL = @strSQL + ' ASE.IDServicio = S.IDServicio '
SET @strSQL = @strSQL + ' and ASE.IdServicio = SS.IDServicio '
SET @strSQL = @strSQL + ' and ASE.IdSubServicio = SS.IDSubservicio'
SET @strSQL = @strSQL + 'and RAD.IdSubServicio = SS.IDSubservicio'
SET @strSQL = @strSQL + 'and ASE.FechaFin>=convert(varchar(2),datepart(mm,@Fech aHoy)),'
SET @strSQL = @strSQL + '+convert(varchar(2),datepart(dd,@FechaHoy))+ convert(varchar(4),datepart(yyyy,@FechaHoy))'


if len(@IDSubServicio)>0
BEGIN
SET @strSQL = @strSQL + 'and R.IdSubServicio = ' + cast(@IDSubServicio as varchar(6))
END

SET @strSQL = @strSQL + 'and S.IdServicio = SubS.IdServicio'

if len(@IDServicio)>0
BEGIN
SET @strSQL = @strSQL + 'and S.IdServicio = ' + cast(@IDServicio as varchar(3))
END

SET @strSQL = @strSQL + 'and R.IdInstalacion = I.IdInstalacion'

if len(@IDInstalacion)>0
BEGIN
SET @strSQL = @strSQL + 'and R.IdInstalacion = ' + cast(@IDInstalacion as varchar(3))
END

SET @strSQL = @strSQL + 'and C.IdCategoria = U.IdCategoria'

if len(@IDCategoria)>0

BEGIN
SET @strSQL = @strSQL + 'and C.IdCategoria = ' + cast(@IDCategoria as varchar(2))
END

SET @strSQL = @strSQL + 'and F.IdFederacion= U.IdFederacion'

if len(@IDFederacion)>0
BEGIN
SET @strSQL = @strSQL + 'and F.IdFederacion= ' + cast(@IDFederacion as varchar(2))
END

SET @strSQL = @strSQL + 'and U.IdEspecialidad= Esp.IdEspecialidad'

if len(@IDEspecialidad)>0
BEGIN
SET @strSQL = @strSQL + 'and U.IdEspecialidad= ' + cast(@IDEspecialidad as varchar(2))
END

SET @strSQL = @strSQL + 'and U.IdEstatus= E.IdEstatus'

if len(@NUsuario)>0

BEGIN
SET @strSQL = @strSQL + 'and U.NumeroAtleta = ' + cast(@NUsuario as varchar(6))
END

if len(@NSoporte) > 0
BEGIN
SET @strSQL = @strSQL + 'and R.IdSoporteServicio = ' + cast(@NSoporte as varchar(6))
END
exec (@strSQL)
if len(@Curp)>0
BEGIN
delete from TempResumenOtorgados
where CURP <> @CURP
and UsuarioActivo=@UsuarioActivo
END
If len(@FechaInicial)>0
BEGIN
Select Instalacion,Federacion,
convert(varchar(2),datepart(mm,FechaInicio)) + '/'+ convert(varchar(2),datepart(dd,FechaInicio)) + '/'+ convert(varchar(4),datepart(yyyy,FechaInicio)),
convert(varchar(2),datepart(mm,FechaFin)) + '/'+ convert(varchar(2),datepart(dd,FechaFin)) + '/'+ convert(varchar(4),datepart(yyyy,FechaFin)),
Servicio,
Subservicio,Nombre,ApellidoPaterno,ApellidoMaterno ,IDSoporteServicio,NumeroAtleta,
CURP,IDCategoria,IDEspecialidad,IDFederacion,IDSer vicio,IDSubservicio,UsuarioActivo,IDInstalacion,
Habitacion,Sexo,IDUsuario
from TempRServiciosProgramados
where UsuarioActivo=@UsuarioActivo
order by IDInstalacion,IDFederacion,IDServicio,IDSubservici o,FechaInicio,NumeroAtleta,IDSoporteServicio
END
else
BEGIN
Select Instalacion,Federacion,
convert(varchar(2),datepart(mm,FechaInicio)) + '/'+ convert(varchar(2),datepart(dd,FechaInicio)) + '/'+ convert(varchar(4),datepart(yyyy,FechaInicio)),
convert(varchar(2),datepart(mm,FechaFin)) + '/'+ convert(varchar(2),datepart(dd,FechaFin)) + '/'+ convert(varchar(4),datepart(yyyy,FechaFin)),
Servicio,
Subservicio,Nombre,ApellidoPaterno,ApellidoMaterno ,IDSoporteServicio,NumeroAtleta,
CURP,IDCategoria,IDEspecialidad,IDFederacion,IDSer vicio,IDSubservicio,UsuarioActivo,IDInstalacion,
Habitacion,Sexo,IDUsuario
from TempRServiciosProgramados
where UsuarioActivo=@UsuarioActivo
order by IDInstalacion,IDFederacion,IDServicio,IDSubservici o,FechaInicio,NumeroAtleta,IDSoporteServicio
END
END
if @accion=2
begin
Select A.Estatus
from AsignacionServicio as AB,Actividad A
where AB.IDUsuario=@IDUsuario
and AB.IDSoporteServicio=@NSoporte
and AB.IDSoporteServicio=A.IDSoporteServicio
and AB.IDAsignacionServicio=A.IDAsignacionServicio
and AB.IDServicio is null
order by A.Estatus
end
return 0
GO
  #4 (permalink)  
Antiguo 24/04/2008, 15:09
Avatar de flaviovich  
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 8 meses
Puntos: 39
Re: Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

Si cambias @accion int por @accion int null ya no tendras ese problema.
Ahora la pregunta seria se puede dar ese caso?
Asi como tienes tu SP @accion es parametro obligatorio.
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.
  #5 (permalink)  
Antiguo 24/04/2008, 15:15
 
Fecha de Ingreso: abril-2008
Ubicación: MEXICO D.F.
Mensajes: 22
Antigüedad: 16 años
Puntos: 0
Exclamación Re: Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

Ya intente eso del NULL y si como dices ya no tiene problemas pero el resultado al mandar llamar al prodecure deberia ser todo lo que se especifica en el select y no lo hace unicamente pone en el resultado " Comandos completados con éxito." Eso es lo malo
Si tienes alguna otra sugerencia te lo agradecería

alegna
  #6 (permalink)  
Antiguo 24/04/2008, 15:39
Avatar de flaviovich  
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 8 meses
Puntos: 39
Re: Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

Amigo alegna_13, tienes aumentar codigo a tu SP para el caso que la accion tenga un valor null.
Y te repito, no le estas pasando el valor de accion. Segun vi, accion toma dos valores: 1 y 2.
A ver muestra como llamas al SP.
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.
  #7 (permalink)  
Antiguo 24/04/2008, 15:42
 
Fecha de Ingreso: abril-2008
Ubicación: MEXICO D.F.
Mensajes: 22
Antigüedad: 16 años
Puntos: 0
Exclamación Re: Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

HOLA DE NUEVO !!!

Pues resulta que despues de mucho pensarle y moverle para tratar de sacar algun resultado ví que declarando ambas variables que ocupo de @accion el resultado fue bueno; me trajo toda la informacion del select. No tengo idea si esto ya este bien asi tendría que revisarlo con mi jefa pero por el momento sería una solucion tentativa.

--------------------------
@accion int=1,
@accion_s int=2,
---------------------------



Si tienen alguna otra solucion se las agradecería


alegna
  #8 (permalink)  
Antiguo 24/04/2008, 15:48
 
Fecha de Ingreso: abril-2008
Ubicación: MEXICO D.F.
Mensajes: 22
Antigüedad: 16 años
Puntos: 0
Exclamación Re: Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

PARA LLAMAR AL STORE UNICAMENTE LO LLAMO CON EL NOMBRE :

-------------------------------------------------
sp_RServiciosProgramados_mod

---------------------------------------------------

Asi es como logre que me mostrara las columnas. Eso esta mal???


alegna

P.D. Te agradezco tu tiempo para revisar el stored
  #9 (permalink)  
Antiguo 24/04/2008, 15:54
Avatar de flaviovich  
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 8 meses
Puntos: 39
Re: Problemas Con Parametros En El Stored Procedure!!!!!!!!!!!

Creo que ya entendi lo que querias. Tu querias que al no pasarle la accion se ejecute ambos bloques (cuando accion es 1 y 2), cierto? Si es asi pon:
Código:
...
if @accion=1 OR @accion IS NULL
...
if @accion=2 OR @accion IS NULL
Suerte!
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 18:45.