DATE

  • Hi all,

    WOULD IF I CAN HELP WITH THAT, I HAVE MY INNER JOIN TABLE EXISTENCIA_BODEGA WITH THE TABLES AND CELLAR TRANSACCION_INV, I WANT TO BRING IS ALL THAT HAD LAST ARTICLE TRANSACTION, SO HAVE FECHA_HORA_TRANSAC COLUMN, BUT I IS BRINGING ALL THE TRANSACTION, COULD GUIDE ME ON HOW I CAN TELL ME BRING SQL TRANSACTIONS OF EVERY lAST ARTICLE.

    HOW CAN SEE I HAVE A COLUMN BETWEEN A FECHA_HORA_TRANSAC FOR ME TO BRING THE 17/10/2013 2013-10-01, SHOULD COMPLY WITH THESE CONDITIONS.

    THANK YOU,

    GREETINGS

  • To help us help you, rather than posting a picture of the data, please see the first link under "Helpful Links" in my signature line below and post your data as per that article. Otherwise the answer is simply, express a ROW_NUMBER() over the partitions formed by the articulo column in descending order by fecha_hora_transac in a CTE and select only the rows with a ROW_NUMBER() of "1" from that.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • It looks like something along those lines might help (untested due to missing sample data in a ready to use format...):

    WITH cte AS

    (

    SELECT DISTINCT articulo

    FROM unknown

    )

    SELECT

    uk.articulo,

    uk.bodega,

    uk.cant_disponible,

    uk.cantidad,

    uk.fecha_hora_transac

    FROM cte

    CROSS APPLY

    (

    SELECT TOP 1

    u.articulo,

    u.bodega,

    u.cant_disponible,

    u.cantidad,

    u.fecha_hora_transac

    FROM unknown u

    INNER JOIN cte ON cte.articulo = u.articulo

    ORDER BY u.fecha_hora_transac DESC

    )uk

    If there's already a normalized table to get the articulo values, use this table instead of the cte.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply