SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO
如题,我的代码有问题吗
CREATE PROCEDURE [dbo].[SETONLINE](@OperateType int, @CategoryID int)
AS
BEGIN
print '123'
print @OperateType


print @CategoryID
Declare @tmpID INT,@state INT
IF @OperateType=1 
UPDATE menus SET menustate=menustate |2 WHERE id=@CategoryID
ELSE IF @OperateType=0
UPDATE menus SET menustate=menustate ^2 WHERE id=@CategoryID

Declare c_cursor Cursor For Select Distinct id,menustate FROM menus Where id=@CategoryID

OPEN c_cursor
Fetch Next From c_cursor into @tmpID,@state

While(@@FETCH_STATUS=0)
Begin
IF @OperateType=1 AND (@state&2)<>2

UPDATE MENUS SET menustate=@state|2 Where id=@tmpID
Else IF @OperateType=0 AND (@state&2)=2
UPDATE MENUS SET menustate=@state^2 Where id=@tmpID
End
Close c_cursor
Deallocate c_cursorEND

解决方案 »

  1.   

    Fetch Next From c_cursor into @tmpID,@state While(@@FETCH_STATUS=0) 
    Begin 
       IF @OperateType=1 AND (@state&2) <>2 
          UPDATE MENUS SET menustate=@state|2 Where id=@tmpID 
       Else IF @OperateType=0 AND (@state&2)=2 
          UPDATE MENUS SET menustate=@state^2 Where id=@tmpID    Fetch Next From c_cursor into @tmpID,@state  --加上这句
    End