Ver Mensaje Individual
  #8 (permalink)  
Antiguo 25/09/2006, 07:33
Avatar de Andres95
Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 20 años, 3 meses
Puntos: 38
debido a que el execute se ejecuta en otro contexto diferente al sp que lo está llamando... no puedes compartir ni regresar variables....

para eso tendrias que hacer una tabla temporal y grabar ahi el valor obtenido desde el execute y luego en el sp obtener ese valor.

con tu ejemplo quedaria mas o menos asi...

Código:
DECLARE @vSQL varchar(1000), @posi int, @valor int

If Object_ID ('tempdb..#tmpValor') is not null
	Drop table #tmpValor 

create table #tmpValor (valor int) 

Execute ('Insert into #tmpValor(valor) Select count(*) from ' + @Tabla )

If (Select count(*) from #tmpValor)> 0
Begin
	Select Top 1 @valor = valor from #tmpValor 		
	Set @posi = @nDias % @valor
	Execute ('SELECT TOP 1 tope.*  FROM (SELECT TOP ' + CONVERT(varchar,@posi) + ' * FROM ' + @tabla + ' ORDER BY id) AS tope ORDER BY id DESC')
End

If Object_ID ('tempdb..#tmpValor') is not null
	Drop table #tmpValor