i've had a few issues where the xml conversion throws error "Illegal XML character. Had to adjust the query to this:
INSERT INTO ReportServer.dbo.VersionStore
( ItemId ,
Name ,
ModifiedDate ,
ModifiedBy ,
InsertedDate ,
Def
)
SELECT ItemID ,
Name ,
ModifiedDate ,
u.UserName ,
GETDATE() InsertedDate ,
CONVERT(XML, ContentFinal) AS ContentXML
FROM dbo.Catalog c
INNER JOIN Users U ON u.UserID = c.ModifiedByID
OUTER APPLY ( SELECT CONVERT(VARBINARY(MAX), [Content]) AS CONTENTVar
) t1
OUTER APPLY ( SELECT CASE WHEN LEFT(ContentVar, 3) = 0xEFBBBF
THEN CONVERT(VARBINARY(MAX), SUBSTRING(ContentVar,
4,
LEN(ContentVar)))
ELSE ContentVar
END AS Content2
) t2
OUTER APPLY ( SELECT CASE WHEN RIGHT(Content2, 1) = 0x00
THEN CONVERT(VARBINARY(MAX), LEFT(Content2,
LEN(Content2)
- 1))
ELSE Content2
END AS ContentFinal
) t3
WHERE Content IS NOT NULL
AND Type != 3
AND ItemID IN (
SELECT c.ItemID
FROM Catalog C
LEFT OUTER JOIN ( SELECT v1.ItemID ,
MAX(v1.modifiedDate) modifiedDate
FROM VersionStore V1
GROUP BY ItemID
) V ON C.ItemID = v.ItemID
WHERE Content IS NOT NULL
AND ( v.itemID IS NULL
OR v.modifiedDate != c.ModifiedDate
) )