This is an example code of what I would like to achieve, I want to add a column to a table with some specific code variables. However, I can't really grasp how the sp_executesql passes it through. Any help appreciated
DECLARE @SQLQUERY NVARCHAR (max)
DECLARE @Table VARCHAR (200) = 'Table_Name'
DECLARE @Column VARCHAR (200) = 'Column_Name'
DECLARE @Code1 int = 1
DECLARE @Code2 int = 2
DECLARE @Code3 int = 3
SET @SQLQUERY = 'ALTER TABLE' + @Table + 'ADD' @Column
AS CASE WHEN FirstColumn IS NULL THEN @Code1
WHEN SecondColumn IS NULL THEN @Code2
ELSE @Code3
Exec sp_executesql @SQLQUERY