0

ストアド プロシージャに問題があります。グループが存在しないかどうかを確認しようとしていuserID & GroupNameます.

ALTER PROCEDURE [dbo].[Insert_Group]
   @UserID uniqueidentifier 
   ,@GroupName varchar(100)
   ,@OutGroupID int out 
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    if not EXISTS(select Groups.id from Groups where Groups.name = @GroupName and Groups.userID = userID)
    begin 
       -- Insert statements for procedure here
       INSERT INTO [ideaPark_DB].[dbo].[Groups]([userID], [name])
       VALUES (@UserID, @GroupName)

       SELECT @OutGroupID = SCOPE_IDENTITY();
    end 
 else 
    SELECT @OutGroupID = (select Groups.id 
                          from Groups 
                          where Groups.name = @GroupName and Groups.userID = userID)
END
4

1 に答える 1

0

質問が何であるかはよくわかりませんが、if not exists 行に @ を追加する必要があるようです:

if not EXISTS(select Groups.id from Groups where Groups.name =@GroupName  and Groups.userID = @userID)

編集:実際には、下部にも1つ欠けているようです。

SELECT @OutGroupID = (select Groups.id 
                      from Groups 
                      where Groups.name = @GroupName and Groups.userID = @userID)
于 2013-06-05T21:02:37.853 に答える