how to compare two table with alerts?
hi,

I have two tables with data.

I want to compare first table of price column and second table of AVG(PRICE) column.

i.e price > AVG(PRICE).

And dispaly the alert message if the condition the true.

how to fid out if any one help this...

April 1st, 2008 10:12pm

You cant do alert on the database side. Basically the database just hold your data. If you want to notify the data changes you can use either Trigger (only notified on the current scope ie, who inserted or updated). If you want to notify to multiple users independent of the scope use the Notification Service. Where you can send a email or message.

I am not sure about your purpose of this action?

Free Windows Admin Tool Kit Click here and download it now
April 2nd, 2008 8:59am

Do you want this comparison to ocurr after data has been manipulated by a user? If so, you can create a stored procedure to update/insert data rows. Then have the procedure evaulate the newly inserted row(s) to see if they fall outside the acceptable scope. If so, use an OUTPUT parameter in the stored procedure to communicate back to the client that the price exceeded the average price.

HTH...

Joe

April 2nd, 2008 3:01pm

This data is real time data. I want to compare that data.

Can u please write a code.

I used trigger, Butits not working.

ALTER TRIGGER averageTrigger ON dbo.averageofclose after insert as

declare @close money

declare @avgclose money

set @close=(select close1 from inserted)

set @avgclose=(select AVERage from inserted)

if @close<@avgclose

begin

declare @msg varchar(50)

set @msg='BUY'

RAISERROR(@msg,16,1);

end

Help me this .....

Free Windows Admin Tool Kit Click here and download it now
April 2nd, 2008 3:08pm

Sameer,

Is this still an issue?

Thanks!

January 13th, 2014 9:42pm

This trigger will work only for single record inserts.

if you want to make it work for set based inserts as well use

ALTER TRIGGER averageTrigger ON dbo.averageofclose 
after insert as

if exists (select 1
from inserted
where close1 < AVERage)
begin

declare @msg varchar(50)

set @msg='BUY'

RAISERROR(@msg,16,1);

end

Free Windows Admin Tool Kit Click here and download it now
January 14th, 2014 1:52am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics