01.
SET
XACT_ABORT
ON
;
02.
03.
IF OBJECT_ID(
'dbo.FolderInfo'
)
IS
NULL
04.
BEGIN
05.
CREATE
TABLE
dbo.FolderInfo
06.
(
07.
FolderID uniqueidentifier
PRIMARY
KEY
08.
,Flags
int
NULL
09.
)
10.
END
11.
12.
DECLARE
@Folders
TABLE
(Id uniqueidentifier
PRIMARY
KEY
)
13.
14.
-- Select folders from UserProfile card
15.
INSERT
@Folders(Id)
16.
SELECT
DISTINCT
DefaultFolderID
17.
FROM
dbo.[dvtable_{C64843C3-484F-45E0-9B8A-900EA91BE54D}]
WITH
(NOLOCK)
18.
WHERE
DefaultFolderID
IS
NOT
NULL
;
19.
20.
BEGIN
TRAN;
21.
22.
-- Backup old folder flags
23.
WITH
UserFoldersTree(FolderID, NestLevel)
24.
AS
25.
(
26.
SELECT
27.
Id
28.
,1
29.
FROM
@Folders
30.
31.
UNION
ALL
32.
33.
SELECT
34.
RowID
35.
,tPrev.NestLevel + 1
36.
FROM
dbo.[dvtable_{FE27631D-EEEA-4E2E-A04C-D4351282FB55}] tFld
WITH
(NOLOCK)
37.
JOIN
UserFoldersTree tPrev
ON
tPrev.FolderID = tFld.ParentTreeRowID
38.
)
39.
INSERT
dbo.FolderInfo
40.
(
41.
FolderID
42.
,Flags
43.
)
44.
SELECT
45.
RowID
46.
,Flags
47.
FROM
dbo.[dvtable_{FE27631D-EEEA-4E2E-A04C-D4351282FB55}] tFld
WITH
(NOLOCK)
48.
LEFT
JOIN
UserFoldersTree tUserFld
ON
tUserFld.FolderID = tFld.RowID
49.
WHERE
tUserFld.FolderID
IS
NULL
50.
51.
-- Switch off Unread count
52.
UPDATE
tFld
53.
SET
Flags =
ISNULL
(tFld.Flags, 0) / 4
-- NO_UNREAD_COUNT flag
54.
FROM
dbo.[dvtable_{FE27631D-EEEA-4E2E-A04C-D4351282FB55}] tFld
WITH
(TABLOCK)
55.
JOIN
dbo.FolderInfo tInfo
WITH
(NOLOCK)
ON
tInfo.FolderID = tFld.RowID
56.
57.
IF @@ERROR <> 0
58.
ROLLBACK
TRAN;
59.
60.
COMMIT
TRAN;