将结果输入表的存储过程
我正在尝试创建一个存储过程,从 C# 程序中获取数据,然后将数据输入到名为 dbo.Results
的表中,从 dbo.People
表中收集 UserID 。
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
当我执行 SQL 查询来创建它返回的过程时
消息 4104,级别 16,状态 1,过程 InsertResults,第 11 行 [批处理起始行 0]
无法绑定多部分标识符“dbo.Results”。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IDENT_CURRENT()
采用字符串,但您忽略了
IDENTITY
列而不是尝试查找它如果您尝试
INSERT ... SELECT
,则不使用VALUES
:(另外,让我想知道当您有两个不同的名为
John Smith
的人。)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 upif you are trying to
INSERT ... SELECT
you don't useVALUES
:(Also, makes me wonder what you expect to happen when you have two different people named
John Smith
.)