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 6577501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:38:41+00:00 2026-05-25T15:38:41+00:00

I need to retrieve data from MsAccess/SQL Server (two separate projects in which I

  • 0

I need to retrieve data from MsAccess/SQL Server (two separate projects in which I face similar problem) using c#.net (3.5), preferably fast and with code that is understandable/maintainable/simple.

I have the following tables with columns. For each, the columns in bold are the key (indexed as well).

  • SKU info (~1000 000 records) : PNO, description,leadtime, price, etcetera
  • Usage information (~200 000 records) : OrderNO, PNO, description,date, quantity, unit of measure, etcetera
  • InterchangeAbility (~100 000 records) : PNO,description (PNO1, description1, etcetera)

The last table indicates that (PNO1, description1) is the successor SKU of (PNO,description). Note that (PNO1, description1) may in turn have a successor as well.

I need to retrieve and store in memory:

  1. All usage
  2. SKU information for any part with for which there is usage (about 20000 parts)
  3. All relevant interchangeability records, which say something about parts for which there was usage or parts that are the successor variants of parts for which there was usage etcetera.
  4. SKU information for any relevant preferred parts (about 2000 parts)

Does anybody have a good maintainable solution for this problem?

The most promising approach seems to be to determine on the database side with SKUs are relevant. Problem is, that relevancy is inductively defined. How to do this?

  • 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-05-25T15:38:42+00:00Added an answer on May 25, 2026 at 3:38 pm

    Attempted to figure out how the problem of finding relevant interchangeability might be solved using a CTE. Quickly got out of hand. You might be able to get something from it still. It shouldn’t be too inefficient, despite it’s size, assuming my thinking isn’t completely wrong.

    Each of the queries inside the CTE is basically a temporary view you can access from the CTE. The Preferred, Roots and HasUsage bits don’t depend on any of the other CTE tables, so they could actually even be views if you needed.

    ;WITH Preferred AS (
       -- Find leaves (Any PNO which replaces a PNO but is never replaced.)
      SELECT PNO1 FROM InterchangeAbility l 
      LEFT JOIN InterchangeAbility r ON l.PNO1 = r.PNO
      WHERE r.PNO IS NULL  
    )
    , Roots AS (
      -- Find roots (Any PNO which gets replaced, but never replaces anything.)
      SELECT PNO FROM InterchangeAbility l
      LEFT JOIN InterchangeAbility R ON l.PNO = r.PNO1
      WHERE r.PNO1 IS NULL
    )
    , HasUsage AS (
       -- Count number of records in usage for each PNO in usage (including 0)
       -- Ideally this step wouldn't be necessary, but a LEFT JOIN isn't allowed in 
       -- The recursive part of a CTE.  There may be a more efficient way around this step.
      SELECT SkuInfo.PNO, COUNT(Usage.PNO) AS num_records
      FROM SkuInfo
      LEFT JOIN Usage ON SkuInfo.PNO = SkuInfo.Usage
      GROUP BY SkuInfo.PNO
    )
    , TreeHasUsage AS (
      -- Traverse from root to leaf, used leaves will have nonzero usage
      -- This is a recursive query, The usage of each root will be the base case.
      SELECT p.PNO AS root, p.PNO AS curr, hu.num_records 
      FROM Roots p
      INNER JOIN HasUsage hu ON p.PNO = hu.PNO 
      UNION ALL
      -- This is the recursive part of the query, it finds the PNO which replaces
      -- the root element (and so on) and does a running total of the usage associated
      -- with this tree branch.  By the time we get to a leaf any relevant preferred PNOs
      -- will have a nonzero num_records.
      SELECT tu.root, hu.PNO, tu.num_records + hu.num_records 
      FROM TreeHasUsage tu 
      INNER JOIN InterchangeAbility i ON tu.curr = i.PNO1 
      INNER JOIN HasUsage hu ON i.PNO = hu.PNO  
    )
    , RelevantRoots AS (
      -- Important tree nodes are the ones which have a non zero 
      -- num_records on one or more leaves. Select the roots of those trees.
      SELECT DISTINCT hu.root FROM Preferred p 
      INNER JOIN TreeHasUsage hu WHERE p.PNO1 = hu.curr
      WHERE hu.num_records > 0 
    )
    -- Select every record in InterchangeAbility which belongs to one of the 
    -- just determined relevant roots.
    SELECT * FROM InterchangeAbility i 
    INNER JOIN RelevantRoots rr ON i.PNO = rr.root
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve a set of Widgets from my data access layer, grouped
I need to retrieve all rows from a table where 2 columns combined are
I need to retrieve a record from a database, display it on a web
I need to launch a server on the remote machine and retrieve the port
I need to retrieve, in my Win32 standalone program, a list of currently installed
I have a HashMap with millions of entries. Need to retrieve all entries whose
I am storing all my passwords in the form hashed. I need to retrieve
I need to run a native program and retrieve the output in an Adobe
Need a function that takes a character as a parameter and returns true if
Need a way to allow sorting except for last item with in a list.

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.