I have the following query in SQL SERVER, I am trying to create variables dynamically
DECLARE @TESTEO NVARCHAR(max)
SET @TESTEO = ‘
DECLARE @SEG1HEM NVARCHAR(max)
SET @SEG1HEM = (SELECT REGION FROM PRUEBA..L3_PRESENTACIONES_OUTLETS_TB WHERE OUTLET_CODE = ”1156”)
PRINT @SEG1HEM
‘
EXEC sp_executesql @TESTEO
PRINT @SEG1HEM
Is it possible to create the variable (“@SEG1HEM”) in this way and use this variable (“@SEG1HEM”) outside of this dynamic script?