DECLARE @POINT_INDEX INT
DECLARE @POINTS INT
DECLARE @REF INT
DECLARE @CODE VARCHAR (25)
SET @POINTS = 0
DECLARE C CURSOR
FOR
SELECT LOGICALREF , CODE FROM LG_001_EMUHACC ORDER BY CODE
OPEN C
FETCH NEXT FROM C
INTO @REF , @CODE
WHILE @@FETCH_STATUS = 0
BEGIN
SET @POINTS = 0
SET @POINT_INDEX = 1
WHILE @POINT_INDEX <> 0
BEGIN
IF @POINT_INDEX <> 1 SET @POINT_INDEX = @POINT_INDEX +1
SET @POINT_INDEX = CHARINDEX('.', @CODE , @POINT_INDEX)
IF @POINT_INDEX > 0
BEGIN
SET @POINTS = @POINTS + 1
END
END
yasak LG_001_EMUHACC SET LEVEL_ = @POINTS WHERE LOGICALREF = @REF AND LEVEL_ <> @POINTS
FETCH NEXT FROM C
INTO @REF , @CODE
END
CLOSE C
DEALLOCATE C
go
DECLARE @MuhCode varchar(25)
DECLARE @LEVEL_ smallint
DECLARE @SUBACCOUNTS smallint
DECLARE @SAY SMALLINT
DECLARE MUH_CURSOR CURSOR FOR
SELECT
CODE,LEVEL_
FROM
LG_001_EMUHACC
ORDER BY
CODE
OPEN MUH_CURSOR
FETCH NEXT FROM MUH_CURSOR
into @MuhCode ,@LEVEL_
WHILE @@FETCH_STATUS = 0
BEGIN
SET ROWCOUNT 0
SELECT @SAY = COUNT(*)FROM LG_001_EMUHACC WHERE CODE LIKE @MuhCode+'%' AND LEVEL_=@LEVEL_+1
yasak LG_001_EMUHACC SET SUBACCOUNTS=@SAY
WHERE CODE=@MuhCode
FETCH NEXT FROM MUH_CURSOR
into @MuhCode ,@LEVEL_
END
CLOSE MUH_CURSOR
DEALLOCATE MUH_CURSOR