SQL Server
SQL Server
Get a Mail-Merge Replacement String by Pattern
See more Email Object Examples
Demonstrates the Chilkat Email.GetReplaceString2 method, which returns the replacement string for a previously-defined pattern/replacement pair, looked up by the pattern itself (a mail-merge feature). This example defines two pairs and looks up the replacement for one pattern by name.
Background: Where
GetReplaceString fetches a replacement by its numeric position, GetReplaceString2 fetches it by the pattern — convenient when you already know the token (say FIRST_NAME) and just want its configured substitution without scanning the whole list.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 GetReplaceString2 method, which returns the replacement string for a
-- previously-defined pattern/replacement pair, looked up by the pattern itself (a
-- mail-merge feature).
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'
-- Look up the replacement for a specific pattern.
DECLARE @repl nvarchar(4000)
EXEC sp_OAMethod @email, 'GetReplaceString2', @repl OUT, 'FIRST_NAME'
PRINT 'FIRST_NAME -> ' + @repl
EXEC @hr = sp_OADestroy @email
END
GO