Howto: trigger get latest record and xp_sendmail it ?

Howto: trigger get latest record and xp_sendmail it ?

Post by Nicolas Verhaegh » Fri, 23 Aug 2002 14:51:04



Tricky: I have a table on a SQL Server with no identity field.

ON INSERT on a table, I need an email to be sent to somebody advising that
some information has been entered.

I therefore need the trigger to extract the information from the newly
inserted record and merge it into a plain English email.

How can this be done, knowing that there is no identity field or anything
incremented, not even a getdate() defaulted field...?

I can handle the master..xpsendmail part :)

Thanks a lot in advance for your help!

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

 
 
 

Howto: trigger get latest record and xp_sendmail it ?

Post by Tibor Karasz » Fri, 23 Aug 2002 15:19:36


Nicolas,

In your INSERT trigger, you have access to a virtual table named inserted. This contains the
rows inserted. Note that there can be several rows, so you might need a cursor to loop this
table and call xp_cmdshell from there. See Books Online for examples on triggers.

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sql...


Quote:> Tricky: I have a table on a SQL Server with no identity field.

> ON INSERT on a table, I need an email to be sent to somebody advising that
> some information has been entered.

> I therefore need the trigger to extract the information from the newly
> inserted record and merge it into a plain English email.

> How can this be done, knowing that there is no identity field or anything
> incremented, not even a getdate() defaulted field...?

> I can handle the master..xpsendmail part :)

> Thanks a lot in advance for your help!

> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


 
 
 

Howto: trigger get latest record and xp_sendmail it ?

Post by Stride » Sat, 24 Aug 2002 12:35:02



Quote:> Tricky: I have a table on a SQL Server with no identity field.

> ON INSERT on a table, I need an email to be sent to somebody advising that
> some information has been entered.

> I therefore need the trigger to extract the information from the newly
> inserted record and merge it into a plain English email.

> How can this be done, knowing that there is no identity field or anything
> incremented, not even a getdate() defaulted field...?

> I can handle the master..xpsendmail part :)

I'd suggest using something other than xpsendmail.  I find it a bit quirky
and sometimes can delay things.  I believe used the way you want to use it
above it's synchronous which could cause performance issues.  I find a
product called BLAT which is a command line email util to be handy.
Quote:

> Thanks a lot in advance for your help!

> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

 
 
 

1. Getting only the latest entries for each parent record from a timestamped table

Hi!

I'm looking for a fast and reliable way to fetch the latest entry pr. parent
record from a table with both current and historic values. Here's an example
of what I'm trying to do - it works, but I'm looking for a better solution:

---

create table #tmp ([id] int identity primary key, [name] varchar(10),
[value] int, [date] datetime)

insert into #tmp ([name], [value], [date]) values ('ab', 1, getdate())
insert into #tmp ([name], [value], [date]) values ('ab', 2, getdate() + 1)
insert into #tmp ([name], [value], [date]) values ('ab', 3, getdate() + 2)

insert into #tmp ([name], [value], [date]) values ('cd', 3, getdate())
insert into #tmp ([name], [value], [date]) values ('cd', 1, getdate() + 1)

-- This is the select statement I'd like to "fix"
select #tmp.[name], #tmp.[value], #tmp.[date]
from #tmp
 inner join (
  select [name], max([date]) [date] from #tmp
  group by [name]
 ) MaxEntry
 on MaxEntry.[name] = #tmp.[name] and #tmp.[date] = MaxEntry.[date]

drop table #tmp

---

Any tips appreciated :)

Lars-Erik

2. autoincrementing file number addend.

3. Getting a record associated with the latest date

4. DBMS and DBPD to merge. Get your free (in the U.S.) subscription here.

5. Getting the serial number of latest inserted record in SP

6. 18278:database log truncated:database:mydb

7. howto get latest date

8. Uv objects Error 39202

9. How can I retrieve the latest record in a list of similar records

10. Prob: Triggers not getting Triggered during Batch Updates

11. Getting the latest identity column value

12. Help, Getting DLL error on recordset after installing latest MDAC components

13. Getting the latest row from a batch