本文介绍了创建查询时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嘿伙计我需要你的帮助,我在创建这个查询时遇到错误。这个查询的作用很简单。它需要3个参数firstname,lastname和guid(唯一数字组合),然后检查该人是否已经存在。如果该人这样做,则输出该人的id,如果没有,则插入该人然后输出新的id。然而,它收到此错误: 消息102,级别15,状态1,过程Check_IF_Person_Exist,第4行 '@附近的语法不正确intPersonID'。 消息137,级别15,状态1,过程Check_IF_Person_Exist,第12行 必须声明标量变量@intPersonID。 消息137,级别15,状态1,过程Check_IF_Person_Exist,第19行 必须声明标量变量@intPersonID。Hey guys i need your help, i am getting errors when creating this query. What this query does is preety simple. It take 3 parameter firstname, lastname and guid(unique number combination), then it check if that person already exists. If the person does, then output the person's id and if not, insert the person then out the new id. However, it get this error:Msg 102, Level 15, State 1, Procedure Check_IF_Person_Exist, Line 4Incorrect syntax near '@intPersonID'.Msg 137, Level 15, State 1, Procedure Check_IF_Person_Exist, Line 12Must declare the scalar variable "@intPersonID".Msg 137, Level 15, State 1, Procedure Check_IF_Person_Exist, Line 19Must declare the scalar variable "@intPersonID".Create Procedure Check_IF_Person_Exist(@FirstName nvarchar(50),@LastName nvarchar (50),@Guid int(11))@intPersonID int OUTPUTASBEGINIF EXISTS( SELECT ID FROM ITTESI_AssetTracker_Person WHERE Guid = @Guid)BEGIN -- Assign existing PersonID to output parameter @intPersonIDSET @intPersonID = @@IDENTITYENDELSEBEGININSERT INTO ITTESI_AssetTracker_Person VALUES (@Guid,@FirstName,@LastName)-- Assign newly generated PersonID to output parameter @intPersonIDSET @intPersonID = @@IDENTITYENDEND 感谢您的帮助。Thanks for your help.推荐答案您需要添加: DECLARE @intPersonID intYou need to add this:DECLARE @intPersonID intCreate Procedure [dbo].[Check_IF_Person_Exist]@FirstName nvarchar(50),@LastName nvarchar (50),@Guid int(11)ASDECLARE @intPersonID intBEGINIF EXISTS( SELECT ID FROM ITTESI_AssetTracker_Person WHERE Guid = @Guid)BEGIN -- Assign existing PersonID to output parameter @intPersonIDSET @intPersonID = @@IDENTITYENDELSEBEGININSERT INTO ITTESI_AssetTracker_Person VALUES (@Guid,@FirstName,@LastName)-- Assign newly generated PersonID to output parameter @intPersonIDSET @intPersonID = @@IDENTITYENDEND 这篇关于创建查询时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS!
05-22 14:28