Question: I've got a peculiar requirement where I need to declare a local variable multiple times
in a stored procedure. In t-sql the variables don't go out of scope logically. what is the best way to de-scope a local variable so that a new local variable with the same name can be declared again.

```
IF DATEPART(weekday, GETDATE()) = 5
    BEGIN 
      Declare @Num int
      Declare @year int      
    END
ELSE 
    BEGIN
      Declare @Num int   -- gives an error, the previously declared variable is still active
      Declare @year int  -- gives an error, the previously declared variable is still active
    END     

```

How do I change my Sp so the error does not occur. I do need to declare the local variable twice.

Thanks.

Answer: 
If the variables represent the same thing, just declare them outside the `IF` statement and "re-use" them. 

```
Declare @Num INT, @year INT
IF DATEPART(weekday, GETDATE()) = 5
    BEGIN  
        SET @Num = 1
        SET @year = 2012   
    END
ELSE 
    BEGIN         
        SET @Num = 2
        SET @year = 2013 
    END     

```

If they don't represent the same thing then give them different names.
Also, to build on [Dave K's answer](https://stackoverflow.com/a/18187263/2217305), you can reset the values in a stored procedure of a declared variable. If you want to later use `@num` to be something else, for instance a 5 instead of a 0, you can do that.

```
CREATE PROCEDURE stp_CheckItOut
AS
BEGIN

    DECLARE @date DATE, @number INT, @v VARCHAR(10)
    SET @date = GETDATE()
    SET @number = 1
    SET @v = 'Dog'

    SELECT @date, @number, @v

    -- Reset variables by setting them to NULLs
    SET @date = NULL
    SET @number = NULL
    SET @v = NULL

    SET @date = DATEADD(DD,10,GETDATE())
    SET @number = 4
    SET @v = 'Cat'

    SELECT @date, @number, @v

    -- Reset variables directly
    SET @date = DATEADD(DD,30,GETDATE())
    SET @number = 0
    SET @v = 'Bird'

    SELECT @date, @number, @v

END

EXECUTE stp_CheckItOut

DROP PROCEDURE stp_CheckItOut

```

Provided that a variable remains the same type, you can set it equal to something else later in your code.