Results 1 to 3 of 3

Thread: How do I get these select statements into two separate variables or comparison

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    I have a stored procedure. I need to get the two select statements into variables. I need to compare both counts and create and error rountine if they do not much. I am enclosing the code, but would also like help on the error handler;

    Please assist thanks

    CREATE procedure dbo.SpLaLaMonitor
    @TestDate smalldatetime= '11/24/00 11:00'

    SELECT COUNT (*)as 'what does text here produce?' from dev1.dbo.vw_look_txn Where vendor_err='x' and created_dt>@TestDate

    SELECT COUNT (*) as 'what does text here produce?' from Merchant_Order mo join Order_Line ol on ol.Order_ID = mo.Order_ID Where La_To_La=1 and mo.Modified_Date>@TestDate


    EXEC dbo.SpLaLaMonitor

    --GO

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You can do something like this:
    Code:
    CREATE procedure dbo.SpLaLaMonitor 
    
    @TestDate smalldatetime= '11/24/00 11:00' 
    
    AS
    
    Declare @Result1 int
    Declare @Result2 int
    
    SELECT
        @Result1 = COUNT(*) 
    FROM
        dev1.dbo.vw_look_txn 
    WHERE
        vendor_err='x' and created_dt > @TestDate 
    
    SELECT
        @Result2 = COUNT(*) 
    FROM
        Merchant_Order mo join Order_Line ol on ol.Order_ID = mo.Order_ID 
    WHERE
        La_To_La = 1 and mo.Modified_Date > @TestDate 
    
    
    If @Result1 <> @Result2
        Begin
            Return 1000 --Return any error number you want
        End
    Else
        Begin
            Return 0  --Return success number here
        End

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    "I wanna be like Mike"

    Quote from Volcano when Tommy Lee Jones saves city from Volcano and reroutes it to ocean.


    You are awesome thanks!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width