Ver Mensaje Individual
  #4 (permalink)  
Antiguo 30/09/2014, 08:53
Avatar de iislas
iislas
Colaborador
 
Fecha de Ingreso: julio-2007
Ubicación: Mexico, D.F.
Mensajes: 6.482
Antigüedad: 16 años, 10 meses
Puntos: 180
Respuesta: Update SQL dinamico

Debes leer un poco mas sobre el procedimiento sp_executesql:

Código SQL:
Ver original
  1. DECLARE @IntVariable INT;
  2. DECLARE @SQLString nvarchar(500);
  3. DECLARE @ParmDefinition nvarchar(500);
  4.  
  5. /* Build the SQL string one time.*/
  6. SET @SQLString =
  7.      N'SELECT BusinessEntityID, NationalIDNumber, JobTitle, LoginID
  8.       FROM AdventureWorks2012.HumanResources.Employee
  9.       WHERE BusinessEntityID = @BusinessEntityID';
  10. SET @ParmDefinition = N'@BusinessEntityID tinyint';
  11. /* Execute the string with the first parameter value. */
  12. SET @IntVariable = 197;
  13. EXECUTE sp_executesql @SQLString, @ParmDefinition,
  14.                       @BusinessEntityID = @IntVariable;
  15. /* Execute the same string with the second parameter value. */
  16. SET @IntVariable = 109;
  17. EXECUTE sp_executesql @SQLString, @ParmDefinition,
  18.                       @BusinessEntityID = @IntVariable;

Para saber mas:

http://msdn.microsoft.com/es-mx/library/ms188001.aspx
__________________
MCTS Isaias Islas