host
DECLARE @InsertStatement NVARCHAR(MAX); SELECT @InsertStatement = 'INSERT INTO SalesEmployees (Id, Name, Age) ' + 'SELECT ' + STRING_AGG('''' + CAST(Id AS NVARCHAR(MAX)) + '''', ', ') + ' FROM Employees WHERE Department = ''Sales'';' FROM Employees WHERE Department = 'Sales'; PRINT @InsertStatement;