query request - Page 2
DBAsupport.com Forums - Powered by vBulletin
Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: query request

  1. #11
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401
    1.yes it can be reprocessed multiple times but rarely happens
    2.yes it's date datetype

  2. #12
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    Assuming you have no more than one reprocess per orderid/orderstageid query below should work. If you can have more than one reprocess per orderid/orderstageid additional logic is needed to sort out different reprocess items.

    Code:
    select  a.orderid,
            a.orderstageid,
            a.processdate,
            a.orderinfo
    from    order_history a
    where   a.orderid || a.orderstageid = (select   b.orderid || b.orderstageid
                                           from     order_history b
                                           where    a.orderid || a.orderstageid = b.orderid || b.orderstageid
                                           and      b.orderinfo = 'reprocessed')
      and   a.orderinfo   <> 'reprocessed'
      and   a.processdate >= (select   c.processdate
                              from     order_history c
                              where    a.orderid || a.orderstageid = c.orderid || c.orderstageid
                              and      c.orderinfo = 'reprocessed')
    ;
    Hope this helps.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

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