SQL Server
SQL Server
Get a Mail-Merge Replace Pattern
See more Email Object Examples
Demonstrates the Chilkat Email.GetReplacePattern method, which returns a replacement pattern — the search string — previously defined for mail-merge operations with SetReplacePattern. The index is zero-based. This example defines two patterns and enumerates them.
Background: In Chilkat's mail-merge, each entry is a pattern (a placeholder token such as
FIRST_NAME) paired with a replacement string. GetReplacePattern retrieves the search side of the pair at a given index; GetReplaceString retrieves the matching replacement. Reading them back is useful for inspecting or logging exactly which substitutions will be applied when the message is sent.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
-- Demonstrates the GetReplacePattern method, which returns a replacement pattern (the
-- search string) previously defined for mail-merge operations with SetReplacePattern.
-- The index is zero-based.
DECLARE @email int
EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @email, 'Subject', 'Hello FIRST_NAME'
EXEC sp_OASetProperty @email, 'Body', 'Dear FIRST_NAME, welcome to CITY.'
DECLARE @success int
EXEC sp_OAMethod @email, 'SetReplacePattern', @success OUT, 'FIRST_NAME', 'John'
EXEC sp_OAMethod @email, 'SetReplacePattern', @success OUT, 'CITY', 'Denver'
DECLARE @n int
EXEC sp_OAGetProperty @email, 'NumReplacePatterns', @n OUT
DECLARE @i int
SELECT @i = 0
WHILE @i <= @n - 1
BEGIN
EXEC sp_OAMethod @email, 'GetReplacePattern', @sTmp0 OUT, @i
PRINT 'Pattern ' + @i + ': ' + @sTmp0
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @email
END
GO