Persist a variable across GO

Costas

Administrator
Staff member
JavaScript:
-- src - https://stackoverflow.com/a/937995
--
-- you cant use 'temporary table variable'  aka @variables
-- as doesnt exist after GO - https://www.pipiscrew.com/2020/11/temporary-tables-vs-table-variables-in-sql-server/

CREATE TABLE #variables
    (
    VarName VARCHAR(20) PRIMARY KEY,
    Value VARCHAR(255)
    )
GO

Insert into #variables Select 'Bob', 'SweetDB'
GO

Select Value From #variables Where VarName = 'Bob'
GO

DROP TABLE #variables
go
 
Top