Home > Net >  Stored procedure to enter Results into a table
Stored procedure to enter Results into a table

Time:03-16

I am attempting to create a stored procedure take the data from a C# program and then input the data into a table called dbo.Results gathering the UserID from the dbo.People table.

create Procedure InsertResults
    @ForName nvarchar(50),
    @Surname nvarchar(50)
    @RaceID int,
    @Place int,
    @Fleet nchar(10)
AS
Begin

Insert Into [dbo].[Results] values
    (IDENT_CURRENT(dbo.Results),@RaceID,(Select UserID From dbo.People Where (ForName = @ForName and Surname = @Surname)),@Place,@Fleet)
End

Where when I execute the SQL Query to create the Procedure it returns

Msg 4104, Level 16, State 1, Procedure InsertResults, Line 11 [Batch Start Line 0]
The multi-part identifier "dbo.Results" could not be bound.

CodePudding user response:

  • IDENT_CURRENT() takes a string, but you don't want to do that anyway

  • you leave out the IDENTITY column rather than trying to look it up

  • if you are trying to INSERT ... SELECT you don't use VALUES:

    INSERT dbo.Results(all,cols,except,identity)
      SELECT @RaceID,UserID,@Place,@Fleet
        FROM dbo.People 
        WHERE ForName = @ForName 
          AND Surname = @Surname;
    

(Also, makes me wonder what you expect to happen when you have two different people named John Smith.)

  • Related