SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DATE


DATE

Author
Message
angelreynosog
angelreynosog
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 85
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

Attachments
AYUDA.jpg (10 views, 287.00 KB)
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (209K reputation)SSC Guru (209K reputation)SSC Guru (209K reputation)SSC Guru (209K reputation)SSC Guru (209K reputation)SSC Guru (209K reputation)SSC Guru (209K reputation)SSC Guru (209K reputation)

Group: General Forum Members
Points: 209591 Visits: 41973
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
LutzM
LutzM
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23101 Visits: 13559
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
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search