i got
Msg 156, Level 15, State 1, Procedure Flag_Account, Line 21 Incorrect syntax near the keyword 'while'. Msg 156, Level 15, State 1, Procedure Flag_Account, Line 23 Incorrect syntax near the keyword 'select'.
when i try to run
USE [hesabat2]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[Flag_Account]
AS
begin
DECLARE @Acc_link int, @Result int,@inc int,@Result2 int
SET @inc = 0
set @Result =0
DECLARE A_Cursor CURSOR FOR
Select account_id FROM ACCOUNTS
OPEN A_Cursor
FETCH NEXT FROM A_Cursor INTO @Acc_link
WHILE (@@FETCH_STATUS =0)
BEGIN
set @Result= (select a.account_link from ACCOUNTS a where account_id= @Acc_link
while(@Result = 0)
begin
set @Result = select a.account_link from ACCOUNTS a where account_id=@Result
SET @inc= @inc+1
end
update ACCOUNTS set flag_color=@inc where account_id= @Acc_link
FETCH NEXT FROM A_Cursor INTO @Acc_link
END
CLOSE A_Cursor
DEALLOCATE A_Cursor
end