I am glad that I could help.
""Sokrates"" <somebody@somewhere.earth> wrote in message
news:eio$j27BEHA.3472@TK2MSFTNGP09.phx.gbl...
> WOW,
>
> This has really been a GREAT experience reading the code you send, thanx
> alot! I went through it line after line a dusin of times, and now I get
most
> of it - it's kinda beautiful actually...
>
> I finally get it - the store procedure thing, the cursor and so on - I
> really like it, and I must say - this opens up thousands of
possibilities!!!
>
> The best thing is, that I learned a few things - but futher more, I
created
> a SP that saves us and our customers lots of lots of time and trouble!
>
> Again - Thanx alot!
>
> Best regards
> Jakob
>
>
> ""Sokrates"" <somebody@somewhere.earth> skrev i en meddelelse
> news:OIy0BB2BEHA.3804@TK2MSFTNGP09.phx.gbl...
> > Wow - that is pretty advanced in my eyes...
> > Does it create a Stored Procedure? This has to run only once right?
> >
> > Could you (or somebody else) show me how to do it from a table ORDERS
> > containing
> > ORDERNO, INVOICENO, TRACKNTRACE, EMAIL, COMPANYNAME
> >
> > Just a simple email with one of the above cols in the email subject or
> > body...?
> >
> > Pleeease ;)
> > Jakob
> >
> >
> >
> > "Prasad Koukuntla" <prasad.koukuntla@scapromo.com> skrev i en meddelelse
> > news:%23SeCgNvBEHA.2380@TK2MSFTNGP10.phx.gbl...
> > > Sokrates,
> > > Use the following as an example. This stored procedure uses the email
> > > addresses from my database and sends email using xp_smtp_sendmail .
> > > HTH
> > > Prasad Koukuntla.
> > >
> > >
> > > CREATE PROC SP_XXXXXXX
> > > AS
> > > SET NOCOUNT ON
> > >
> > > /**Get the all the new contacts that qualify**/
> > > DECLARE @LastName varchar(100), @FirstName varchar(100), @Company
> > > varchar(150), @NEXT_KEY int,
> > > @SalesRep varchar(100), @EmailAddress varchar(150),
@Listing_ID
> > int,
> > > @msg nvarchar(4000),
> > > @From varchar(400), @FromName varchar(400), @ReplyTo
> varchar(300),
> > > @BCC varchar(300),
> > > @RecepientList varchar(400), @Subject varchar(300), @RC int,
> > > @Domain_name varchar(200), @body varchar(3000),
> > > @title varchar(80), @header varchar(10), @signature
varchar(10)
> > >
> > > SET @BCC = 'mailers@xxxxxx.com'
> > > SET @Subject = 'Thank you for your interest in XXX'
> > > SET @Domain_name = '@xxxxx.com'
> > >
> > > SET @body = N'<P>Thank you for your interest in XXXX. '
> > > SET @body = @body + N'Please feel free to use <a
> > href="http://www.xxxxx.com"
> > > >www.xxxxx.com</a> '
> > > SET @body = @body + N'as a resource <br>for promotion ideas. </P>'
> > >
> > > SET @body = @body + N'<P></P><P><a
> > href="
http://www.xxxxxxx.com/subscribe">'
> > > SET @body = @body + N'Click here</a> to subscribe to our quarterly
> > > newsletter '
> > > SET @body = @body + N'and to receive great promotion ideas targeted to
> > your
> > > industry <br> via '
> > > SET @body = @body + N'mail or e-mail.</P>'
> > > SET @body = @body + N'<P></P><P>If there is anything else '
> > > SET @body = @body + N'I can do to assist you, please feel free to
> contact
> > me
> > > anytime. </P>'
> > > SET @body = @body + N'<P></P><P>I look forward to working with you in
> the
> > > future.</P><P></P>Best regards,'
> > >
> > > DECLARE SEND_EMAIL CURSOR
> > > FOR
> > > SELECT
> > > LAST_NM LastName,
> > > FIRST_NM FirstName,
> > > COMPANY_NM Company,
> > > e.lst_custom_enum_nm SalesRep,
> > > iae.ELEC_ADDR EMailAddress,
> > > i.Listing_ID
> > > FROM INT_AUX_LISTING I LEFT JOIN INT_AUX_LST_CUSTOM lc
> > > LEFT JOIN
> > > INT_LST_CUSTOM_DEF c ON
> > > (c.lst_custom_def_id = lc.lst_custom_def_id)
> > > LEFT OUTER JOIN
> > > INT_LST_CUSTOM_ENUM e ON
> > > (c.lst_custom_def_id = e.lst_custom_def_id and
> > >
> > > e.lst_custom_enum_id=lc.lst_custom_enum_id)
> > > ON (lc.listing_id = i.listing_id and
> > c.label
> > > = '1. Sales Rep 1')
> > > LEFT OUTER JOIN (INT_AUX_LST_EADDR ea
> > > inner join INT_AUX_ELEC_ADDR
iae
> on
> > > (iae.ELEC_ADDR_ID = ea.ELEC_ADDR_ID and ELEC_ADDR_TYP_ID = 1))
> > > ON i.listing_id = ea.listing_id and
> > > ea.rltn_typ_id = 1
> > > LEFT JOIN INT_AUX_LST_CUSTOM lc2 left JOIN
> > > INT_LST_CUSTOM_DEF c2
> > > ON
> > > (c2.lst_custom_def_id = lc2.lst_custom_def_id)
> > > left JOIN
> > > INT_LST_CUSTOM_ENUM e2
> > > ON
> > > (c2.lst_custom_def_id = e2.lst_custom_def_id and
> > >
> > > e2.lst_custom_enum_id=lc2.lst_custom_enum_id and e2.LST_CUSTOM_ENUM_NM
> NOT
> > > IN ('Delete Account & All Contacts', 'Delete Contact', 'Inactive',
> > > 'Archive'))
> > > ON (lc2.listing_id = i.listing_id and
> > > c2.label = '7. status')
> > >
> > > WHERE I.LISTING_TYP_IND = 0 --Person contacts only
> > > AND CONVERT(VARCHAR(12), I.CREATE_DT, 101) = CONVERT(VARCHAR(12),
> > > GETDATE(), 101)
> > > AND i.COMPANY_NM NOT LIKE 'XXX%'
> > > AND iae.ELEC_ADDR IS NOT NULL
> > > AND (e.lst_custom_enum_nm NOT IN ('Non-Sales',
> Unassigned' ) --Exclude
> > > these SalesReps
> > > OR e.lst_custom_enum_nm IS NULL) AND NOT EXISTS (SELECT *
FROM
> > > INT_AUX_DIR_LIST e
> > > WHERE CONTAIN_DIR_ID = 137 --Auto Email (Do Not
Send)
> > > and e.listing_id = I.listing_id)
> > > AND not exists (select * from INT_AUX_LST_CUSTOM l
> > > WHERE l.LISTING_ID = i.LISTING_ID
> > > AND LST_CUSTOM_DEF_ID = 12 AND LST_CUSTOM_ENUM_ID
=
> > > 237) --Request to be removed from Mailings-E-Mail
> > > AND not exists (select * from INT_AUX_LST_CUSTOM l
> > > WHERE l.LISTING_ID = i.LISTING_ID
> > > AND LST_CUSTOM_DEF_ID = 12 AND LST_CUSTOM_ENUM_ID
=
> > > 341) --Request to be removed from Mailings-ALL
> > > and exists (select *
> > > from INT_AUX_DIR_LIST e1
> > > where OWN_DIR_ID = -2 --search only in people public
> folder
> > > and e1.listing_id = I.listing_id)
> > > and iae.ELEC_ADDR like '%_@%'
> > >
> > >
> > > OPEN SEND_EMAIL
> > >
> > > FETCH NEXT FROM SEND_EMAIL INTO @LastName, @FirstName, @Company,
> > @SalesRep,
> > > @EmailAddress, @Listing_ID
> > >
> > > WHILE (@@FETCH_STATUS = 0)
> > > BEGIN
> > >
> > > IF @SalesRep IS NOT NULL
> > > BEGIN
> > > SET @FromName = @SalesRep