sql server - Executing a SQL statement inside a stored procedure, how to store the result of that SQL statement into a variable for later use? -
I need to execute several SQL status within a stored procedure, save as a result for later use in a variable.
SET Knockout of Declar @ P Table @ P = SELECT d.Periodo [SISACT] DEPRECIACIONES D, [CISACT] .CONTROL_PERIODO C. Where c.vigente = 1 and d.Periodo = c.periodo if @ @ROWCOUNT & gt; 0 Print 'Periodo or Districto' Then I can do something like this later
UPDATE [SISACT] .ACTIVOS_FIJOS set ultimo_periodo = @ p.periodo . .. I know that @ P = SELECT is incorrect , I have seen that they use another stored procedure instead of a SELECT statement, So I should know that this is possible without using a stored procedure, if so, how? I am going to use the query only once in a stored procedure, so I can not find any reason to put it in another stored procedure. I'm new to T-SQL and SQL Server, I'm also learning on my own and I am sorry that this is a stupid question. PS: Only one record should be returned in the query of this case. I am using SQL Server 2008 Express.
Thanks for any help in advance.
I think what you want is what you want. CHAR (6) SELECT p @ = d.Periodo [SISACT] as SET NOCKABET OF DIQUIRT @ P DEPRECIACIONES D, [SISACT] .CONTROL_PERIODO C where c.vigente = 1 and D.Periodo = c.periodo IF @@ ROWCOUNT & gt; 0 print 'Periodo or Districo' and later you can use
UPDATE [SISACT] .ACTIVOS_FIJOS set ultimo_periodo = @ p
Comments
Post a Comment