I am trying to insert values from one table to another one using the following insert sql query
INSERT INTO [dbo].[table2]
SELECT Exec [StoredProcedure],
[Column1]
,[Column2]
FROM [dbo].[table1]
[table2] has the following columns:
- RecNo, <-- INT
- Column1, <--VARCHAR(50)
- Column2 <--VARCHAR(50)
[StoredProcedure] main purpose is that every time a new row to be inserted in table2 it selects the maximum value from RecNo from table2 and adds 1 to that number to create the next number (sequential). Here is the script for the stored procedure .
GO
ALTER PROCEDURE [dbo].[UpdateRcnoNumbers]
@MaxRcno INT OUTPUT
AS
BEGIN
SELECT @MaxRcno=MAX(Recno) FROM [table2]
SELECT @MaxRcno=@MaxRcno+1
RETURN @MaxRcno
END
But I am getting an error and I am not able to call the stored procedure ? Any suggestion please .
Thank you in advance