I am trying to insert data into a SQL Server table using a variable. I tried
DECLARE @table NVARCHAR(50) = 'ToolList',
@val NVARCHAR(50) = 'test'
EXEC ('INSERT INTO ' + @table + 'SELECT ' + @val)
and
EXEC ('INSERT INTO ' + @table + '([col1]) VALUES(' + @val +')'
but still get an error that says
Incorrect syntax near 'test'.
@val nvarchar(50) = ' test 'give space before and aftertest