Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:10:25+00:00 2026-06-17T09:10:25+00:00

UPDATE: It’s now correctly pulling the supplier names for the most recent delivery for

  • 0

UPDATE: It’s now correctly pulling the supplier names for the most recent delivery for each item. The issue I’m having now is that it’s not pulling records that don’t have previous deliveries (blank dlvry_dt). Does anyone know how to fix this?

Thanks a bunch for your help so far!

;WITH Items As(
Select 
a.bin, a.item, d.item_description As 'Vintage', a.min_reorder, 
c.minor_item_class, c.minor_class_description, a.qty_available, 
a.reorder_threshold As 'Par', a.avg_unit_cost, 
a.qty_available*a.avg_unit_cost As 'Valuation', e.dlvry_dt, g.supplier, 
g.supplier_name,
RowNum = ROW_NUMBER() OVER(PARTITION BY a.item ORDER BY dlvry_dt DESC)

from argus.STORE_INVENTORY a, argus.MAJOR_ITEM_CLASS b,
argus.MINOR_ITEM_CLASS c, argus.ITEM_MASTER d, argus.DELIVERY e

inner join argus.delivery_line_item f
on e.delivery = f.delivery
and e.purchase_order = f.purchase_order
and e.customer = f.customer
and e.store = f.store
and e.supplier = f.supplier
full outer join argus.supplier g
on e.supplier = g.supplier


where a.customer = 10005
and a.store = 1
and d.item = a.item
and b.major_item_class = c.major_item_class
and d.minor_item_class = c.minor_item_class
and (b.major_item_class = 15 or b.major_item_class = 17 or b.major_item_class = 14)
and (c.minor_item_class = 830 or c.minor_item_class = 175 or c.minor_item_class = 880 or c.minor_item_class = 661 or c.minor_item_class = 651 or c.minor_item_class = 785 or c.minor_item_class = 716 or c.minor_item_class = 810 or c.minor_item_class = 850 or c.minor_item_class = 885 or c.minor_item_class = 998 or c.minor_item_class = 840 or c.minor_item_class = 855 or c.minor_item_class = 280) 
and f.line_item_status <> 'D'
and e.customer = 10005
and e.store = 1
and f.item = a.item
--and (c.minor_item_class = 176 or c.minor_item_class = 651 or c.minor_item_class = 661 or c.minor_item_class = 716 or c.minor_item_class = 810 or c.minor_item_class = 830 or c.minor_item_class = 840 or c.minor_item_class = 850 or c.minor_item_class = 855 or c.minor_item_class = 885 or c.minor_item_class = 998) 
Group By c.minor_class_description, a.bin, a.item, d.item_description, a.min_reorder, a.qty_available, a.reorder_threshold, a.avg_unit_cost, c.minor_item_class, e.dlvry_dt, g.supplier, g.supplier_name

)
Select bin, item, Vintage, min_reorder, minor_item_class, minor_class_description, qty_available, Par, avg_unit_cost,  Valuation, dlvry_dt, supplier, supplier_name
From Items
Where RowNum =1
Order By minor_class_description
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:10:26+00:00Added an answer on June 17, 2026 at 9:10 am

    One approach would be to use a CTE (Common Table Expression).

    With this CTE, you can partition your data by some criteria – i.e. your Item – and have SQL Server number all your rows starting at 1 for each of those “partitions”, ordered by some criteria.

    So try something like this:

    ;WITH Items AS
    (
       SELECT 
           Item, Vintage, Qty, DeliveryDate,
           RowNum = ROW_NUMBER() OVER(PARTITION BY Item ORDER BY DeliveryDate DESC) 
       FROM 
           dbo.YourTableHere   -- possibly several JOINs
       WHERE
          ......
    )
    SELECT 
       Item, Vintage, Qty, DeliveryDate
    FROM 
       Items
    WHERE
       RowNum = 1
    

    Here, I am selecting only the “first” entry for each “partition” (i.e. for each Item) – ordered by the descending DeliveryDate.

    Does that approach what you’re looking for??

    Update: if you want to include possible NULL entries in DeliveryDate, too, you could use something like

           RowNum = ROW_NUMBER() OVER(PARTITION BY Item ORDER BY ISNULL(DeliveryDate, '99991231' DESC) 
    

    to turn NULL into dates of 31-Dec-9999 – those will always come first when ordered in a descending order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update IV / Current status: I've now confirmed trough another question that the character
UPDATE: I think I have answered most of this question now, except the handling
Update: For anyone having this issue, with the very latest SQLAlchemy this behaviour has
Update : This is no longer an issue from C# 6, which has introduced
UPDATE UPI_ATTRIBUTE SET SITE_INC ='0' WHERE USER_PROFILING_NAME IN ('CAR_IMPLICIT','CAR_EXPLICIT') Above is my query that
UPDATE 6/21/12 I have a form in rails that is working similar to an
UPDATE This would appear to be a issue with background in IE8. CSS3 PIE
Update: Reformulated the question and header: I always thought that expensive android Logging methods
UPDATE: Added doGet function. I have a web app that is used for a
UPDATE : Martin R below has provided a very clear (and succinct!) answer that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.