Hi,
In a stored procedure (MS SQL) I want to update a table to Add columns to it, and then update those new columns with data from a variable.
The problem is that, after updating the table I add a GO, the variable value is loss, but if I don't add the GO I get the error that the column Im adding value to don't exist.
o_O
Example:
Any ideas how to work around this? Thanks!
In a stored procedure (MS SQL) I want to update a table to Add columns to it, and then update those new columns with data from a variable.
The problem is that, after updating the table I add a GO, the variable value is loss, but if I don't add the GO I get the error that the column Im adding value to don't exist.
o_O
Example:
Code:
CREATE PROCEDURE dbo.myProcedure_SP
(
@var1 int = 1,
@var2 int = 1
)
AS
ALTER TABLE myTable
ADD column1 INT NULL
column2 INT NULL,
UPDATE myTable
SET column1 = @var1,
column2 = @var2
GO
EXEC myProcedure_SP
Comment