all groups > sql server programming > september 2007 >
You're in the

sql server programming

group:

Help About Dbmail



Re: Help About Dbmail Dan Guzman
9/9/2007 5:21:22 PM
sql server programming: [quoted text, click to view]

You can SQL Server Agent job with a T-SQL job step that executes a script or
stored procedure.

[quoted text, click to view]

Below is an example to get you started.

CREATE PROCEDURE dbo.usp_Check_Inventory
AS
DECLARE @EmailAddress varchar(128)
IF EXISTS(
SELECT *
FROM dbo.Inventory
WHERE QuantityOnHand <= ReorderQuantity
)
BEGIN
DECLARE EmailAddresses
CURSOR LOCAL FAST_FORWARD FOR
SELECT EmailAddress
FROM Products.dbo.InventoryClerks
OPEN EmailAddresses
WHILE 1 = 1
BEGIN
FETCH NEXT FROM EmailAddresses INTO @EmailAddress
IF @@FETCH_STATUS = -1 BREAK
EXEC msdb.dbo.sp_send_dbmail
@recipients = @EmailAddress,
@subject = 'Reorder Needed',
@body = 'Below is a list of products to reorder.' ,
@query = 'SELECT ProductCode, QuantityOnHand, ReorderQuantity
FROM Products.dbo.Inventory
WHERE QuantityOnHand <= ReorderQuantity'
END
CLOSE EmailAddresses
DEALLOCATE EmailAddresses
END
GO

[quoted text, click to view]

Yes, Database Mail is a feature in Workgroup and above.

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]
Re: Help About Dbmail Dan Guzman
9/9/2007 5:28:14 PM
I forgot to mention that you'll need to enable the Database Mail stored
procedures using the SQL Server Surface Area Configuration Utility. See the
Books Online for more information.

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]
Help About Dbmail The_TOZ
9/9/2007 11:47:40 PM
Hi .
I am new in the sql programming.I need your help..

I want to write a batch procedure that looking for the amount of goods that
under the critical stoke in a table.After find the goods I send email with
Dbmail to email adresses that found on another table.

1-)How can I schedule this job to run hourly?
2-)Can you help me to write the sp?
3-)Can we use dbmail on Sqlserver 2005 Standard Edition?

Thanks for your help..
AddThis Social Bookmark Button