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 anywayyou leave out the
IDENTITY
column rather than trying to look it up- this means you can't be lazy; you need to name your columns
if you are trying to
INSERT ... SELECT
you don't useVALUES
: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
.)