Asi es como lo pongo
Código PHP:
[highlight="sql"]
declare @i as int
Insert into tabla2 (unidades)
SET @i = 1
while @i <= 20
begin exec('select (id' + cast(@i AS varchar) + , valor) )
from tablatemporal
where unidades3 > 0
end
Estos son los errores en esta ocasión , ya ves....
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'SET'.
Msg 137, Level 15, State 1, Line 5
Must declare the scalar variable "@i".
Msg 137, Level 15, State 2, Line 6
Must declare the scalar variable "@i".
Msg 102, Level 15, State 1, Line 7
Incorrect syntax near 'cast'.