Text copied!
DYNAMIC QUERY
Hi! You should also check
INSERT INTO SELECT
syntax first.
DYNAMIC QUERY syntax in SQL
DECLARE @sqlQuery NVARCHAR(MAX); -- Declare the variable to hold the dynamic SQL statement DECLARE @columnNaame NVARCHAR(50) = 'name'; -- Example parameter SET @sqlQuery = 'SELECT ' + @columnName + ' FROM employees'; -- Build the SQL statement dynamically EXECUTE sp_executesql @sqlQuery; -- Execute the dynamic SQL statement
Thank You! You should check
EXCEPTION HANDLING
syntax next.