I am trying to insert a record into a table that was created on the fly. The table is created with errors, and when i check it, all the columns are of the correct data types. I am using the code
ALTER PROCEDURE InsertStudenttoClass
(
@tableName varchar(10),
@StudentID int
)
AS
DECLARE @myStr varchar(1500)
SELECT @mySTR= 'INSERT INTO [dbo].['+@tablename+'] (StudentID) VALUES (@StudentID)'
EXEC (@myStr)
The error messages is telling me to declare the @student variable.
Any ideas?
ALTER PROCEDURE InsertStudenttoClass
(
@tableName varchar(10),
@StudentID int
)
AS
DECLARE @myStr varchar(1500)
SELECT @mySTR= 'INSERT INTO [dbo].['+@tablename+'] (StudentID) VALUES (@StudentID)'
EXEC (@myStr)
The error messages is telling me to declare the @student variable.
Any ideas?