[thelist] sql for mailing list verify

Paul Cowan evolt at funkwit.com
Thu Jul 25 20:54:01 CDT 2002


> I'm using ASP but I see how that relates.  I figured there may be a SQL
> command for it but I guess it doesn't matter as long as it works.  Thanks!

If you're using SQL Server, try

IF (NOT EXISTS(SELECT * FROM MailingList WHERE EmailAddress = 'bob at blah'))
    INSERT INTO MailingList(EmailAddress) VALUES ('bob at blah')

Or, to avoid the conditional logic, which a lot of people don't like, and
make it somewhat more cross-DB-platform-transportable:

INSERT INTO MailingList(EmailAddress)
SELECT
    'bob at blah'
WHERE
    (NOT EXISTS(SELECT * FROM MailingList WHERE EmailAddress = 'bob at blah'))

Hope this helps,

Paul




More information about the thelist mailing list