Ver Mensaje Individual
  #11 (permalink)  
Antiguo 02/10/2014, 08:29
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 9 meses
Puntos: 774
Respuesta: Update SQL dinamico

Cita:
Iniciado por maldini3783 Ver Mensaje

Código SQL:
Ver original
  1. SELECT @TotalOUT=@CountryName
  2.  FROM EC_DashBoard.dbo.DB_TemporalDataPMO  WHERE idstate = @IdState AND @CountryName=@CountryName
tienes varios gaps en esta consulta primero deberia de quedar asi:

Código SQL:
Ver original
  1. DECLARE @query nvarchar(MAX)
  2. SET @query=' Select @TotalOUT=count( ' + CHAR(39) + @CountryName +  CHAR(39) + '
  3. FROM EC_DashBoard.dbo.DB_TemporalDataPMO  WHERE idstate = @IdState and CountryName=' + CHAR(39) +  @CountryName + CHAR(39)

Ahora cuando executas un sp_executesql puedes retornar un valor mira este ejemplo:

Código SQL:
Ver original
  1. CREATE TABLE testing_paises
  2. (
  3. pais VARCHAR(200)
  4. )
  5.  
  6. INSERT INTO testing_paises VALUES ('España')
  7. GO 2
  8. INSERT INTO testing_paises VALUES ('Mexico')
  9. GO 5
  10. INSERT INTO testing_paises VALUES ('Belice')
  11. GO 3
  12.  
  13. CREATE PROCEDURE test_paises (@pais VARCHAR(200), @contador INT output)
  14. AS
  15. DECLARE @query nvarchar(MAX)
  16. DECLARE @ParmDefinition nvarchar(500);
  17.  
  18. SET @query='select @contador=count(*) from testing_paises where pais=' + CHAR(39) +  @pais + CHAR(39)
  19. SET @ParmDefinition = N'@contador int OUTPUT';
  20. EXEC sp_executesql @query,@ParmDefinition, @contador = @contador OUTPUT
  21. RETURN @contador
  22.  
  23.  
  24. DECLARE @contador INT
  25. EXEC test_paises 'Mexico',@contador output
  26. SELECT @contador


fijate como se retornan los valores y como lo estas haciendo tu, para mayor referencia aqui la documentacion oficial del sp_executesql
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me