SQL Server
SQL Server
Subtract One MessageSet from Another
See more IMAP Examples
Demonstrates the Chilkat MessageSet.Subtract method, which removes from this set every identifier whose numeric value is also present in another MessageSet. The only argument is the other set. This example starts with ids 1:10, subtracts 2,4,6, and prints what remains.
Background: A common IMAP pattern is "process everything except what I've already handled."
Subtract makes that a single call: remove the already-processed ids from a working set. The comparison is numeric only and this object's HasUids is preserved, so for meaningful results both sets should hold the same id type from the same mailbox. Passing the same object clears the set; passing an empty set changes nothing.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- Demonstrates the MessageSet.Subtract method, which removes from this set every identifier
-- that is also present in another MessageSet. The only argument is the other MessageSet.
DECLARE @msgSet int
EXEC @hr = sp_OACreate 'Chilkat.MessageSet', @msgSet OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Start with messages 1 through 10.
EXEC sp_OAMethod @msgSet, 'FromCompactString', @success OUT, '1:10'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @msgSet, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @msgSet
RETURN
END
-- The identifiers that have already been processed and should be excluded.
DECLARE @processed int
EXEC @hr = sp_OACreate 'Chilkat.MessageSet', @processed OUT
EXEC sp_OAMethod @processed, 'FromCompactString', @success OUT, '2,4,6'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @processed, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @msgSet
EXEC @hr = sp_OADestroy @processed
RETURN
END
-- Remove the already-processed identifiers from msgSet.
EXEC sp_OAMethod @msgSet, 'Subtract', NULL, @processed
-- Show what remains.
DECLARE @remaining nvarchar(4000)
EXEC sp_OAMethod @msgSet, 'ToCompactString', @remaining OUT
PRINT @remaining
-- Output: 1,3,5,7:10
EXEC @hr = sp_OADestroy @msgSet
EXEC @hr = sp_OADestroy @processed
END
GO