0

Code:

SELECT 
    product_name, model_year, list_price, COUNT(product_name) AS QUANTITY 
FROM
    [production].[products]
GROUP BY 
    model_year, list_price, product_name
HAVING 
    COUNT(product_name) > 1
ORDER BY 
    product_name DESC

I created this SP to make it easy

EXEC SP_CheckQuantity

I want to create a alert that runs every hour and then IF there is a value greater than 5 send me an email

Thank you

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    possible duplicate of :https://stackoverflow.com/questions/47932372/how-to-send-an-e-mail-from-database-if-some-condition-is-met – kiran gadhe Feb 28 '20 at 06:06
  • Side note: you should **not** use the `sp_` prefix for your stored procedures. Microsoft has [reserved that prefix for its own use (see *Naming Stored Procedures*)](http://msdn.microsoft.com/en-us/library/ms190669%28v=sql.105%29.aspx), and you do run the risk of a name clash sometime in the future. [It's also bad for your stored procedure performance](http://www.sqlperformance.com/2012/10/t-sql-queries/sp_prefix). It's best to just simply avoid `sp_` and use something else as a prefix - or no prefix at all! – marc_s Feb 28 '20 at 06:06

0 Answers0