SQL Server
SQL Server
Get MessageSet IDs as a Comma-Separated String
See more IMAP Examples
Demonstrates the Chilkat MessageSet.ToCommaSeparatedStr method, which returns the unique identifiers as a comma-separated string in ascending numeric order. It takes no arguments; an empty set returns an empty string. This example inserts a few ids and prints them.
Background: This is the fully expanded, human-readable form — every identifier listed explicitly, such as
1,2,3,5. It is handy for logging or display. When you need the terse form that collapses consecutive runs into ranges (for example 1:3,5), use ToCompactString instead. Like the compact form, the returned string contains only the numeric values and not the HasUids setting.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
-- Demonstrates the MessageSet.ToCommaSeparatedStr method, which returns the unique identifiers
-- as a comma-separated string in ascending numeric order. It takes no arguments.
DECLARE @msgSet int
EXEC @hr = sp_OACreate 'Chilkat.MessageSet', @msgSet OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Build a set by inserting individual identifiers. The insertion order does not matter;
-- the identifiers are kept in ascending order and duplicates are ignored.
EXEC sp_OAMethod @msgSet, 'InsertId', NULL, 3
EXEC sp_OAMethod @msgSet, 'InsertId', NULL, 1
EXEC sp_OAMethod @msgSet, 'InsertId', NULL, 2
EXEC sp_OAMethod @msgSet, 'InsertId', NULL, 5
-- Get the identifiers as a comma-separated string.
DECLARE @csv nvarchar(4000)
EXEC sp_OAMethod @msgSet, 'ToCommaSeparatedStr', @csv OUT
PRINT @csv
-- Output: 1,2,3,5
EXEC @hr = sp_OADestroy @msgSet
END
GO