CREATE procedure AddReview @id int, @userName varchar(100), @dateReview date, @evaluation int, @description varchar(500) AS BEGIN TRANSACTION BEGIN TRY DECLARE @_name varchar(50) SELECT @_name = _name FROM Fer WHERE id = @id INSERT INTO @_name + 'Review' VALUES (@username, @dateReview, @evaluation, @description) COMMIT END TRY BEGIN CATCH ROLLBACK END CATCH 
  • one
    The name of the table in the query must be fixed, the use of variables and expressions for this purpose is not allowed. If you need to construct a table name dynamically, then create a query entirely in a text variable and execute using sp_executesql - Mike
  • DECLARE @sql varchar (max) = 'INSERT INTO' + @ _ name + 'Review VALUES (' + @ userName + ',' + @ dateReview + ',' + @ evaluation + ',' + @ description + ')' - Andrey
  • one
    But with the values ​​in the parameters, be careful, they will just be text and if they are textual, they should be enclosed in quotes. I would suggest to look at how to pass parameters to sp_executesql - Mike

0