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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:11:10+00:00 2026-05-27T05:11:10+00:00

Sorry for the R101 question. I have a SQL Server 2008 table with a

  • 0

Sorry for the R101 question.

I have a SQL Server 2008 table with a list of items (itemID, Title). I have another table with boxes (boxID, Title). I then have a lookup table that identifies which items go into which boxes.

What is the best way to list all the items with a checkbox checked to show which items are in a box depending on a selected boxID?

Probably a T-SQL statement would be better than a convoluted C# datatable. I’ve had a few attempts but just cant get the right result.

EDIT: Sorry I’ve not been very clear. I need to present a list of all items with a checkbox next to each item. I want checkbox.checked against any item where the boxID has an equivalent item ID next to it in the lookup table.

The result should have have ideally the itemID, itemName and a boolean column to show whether to check the checkbox or not.

The idea is that when the ‘box’ is being updated items can be amended etc.

  • 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-27T05:11:11+00:00Added an answer on May 27, 2026 at 5:11 am

    I suppose you want two things:

    1) A list of all items

    2) A list of all items in boxes

    You can do this in a couple of ways (I’m guessing the structure of your tables here – I’m guessing ItemBox is the link table)

    a) Select all of the items, then select a list of all of the items in boxes:

    SELECT I.ItemID,
           I.Title,
           B.BoxId,
           B.Title
    
    FROM   Item I
    INNER JOIN ItemBox IB ON (I.ItemID = IB.ItemID)
    INNER JOIN Box B ON (IB.BoxID = B.BoxID)
    
    ORDER BY B.Title, I.Title   
    

    Should give you all of the items and their boxes.

    You can then display a list of all items in a form, and a list of box ids (just simple selects from each table).

    If you cache the results from the above query (in say a dictionary, BoxItem dictionary) then you can look up the item quite simply based on the selected Box.

    b) you can run the query each time a box is selected:

    SELECT I.ItemID,
           I.Title,
           B.BoxId,
           B.Title
    
    FROM   Item I
    INNER JOIN ItemBox IB ON (I.ItemID = IB.ItemID)
    INNER JOIN Box B ON (IB.BoxID = B.BoxID)
    
    WHERE B.Id = @selected_boxid
    
    ORDER BY B.Title, I.Title   
    

    And update accordingly.

    Do you need examples for running the query, binding to various controls etc?

    Here’s a version that should do what you want based on your comment:

    SELECT I.ItemID,
          I.Title,
            CASE 
               WHEN IB.ItemID IS NULL THEN 0
               ELSE 1
             END AS ItemIsInBox
    
    
    FROM   Item I
    LEFT OUTER JOIN ItemBox IB ON (I.ItemID = IB.ItemID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the basic question - I'm a .NET developer and don't have much
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry for the long question title. I guess I'm on to a loser on
(sorry about the long title) I have a custom object Person, which in turn
sorry for lamer question, but I really could not found subject. I have a
Sorry to interrupt all of you. I have a question about session. In my
Sorry but yet another question on JavaScript. From my previous post, I was able
Sorry to bother you folks. But i have a simple question. Ho can I
Sorry, I'm a complete noob in configuring SQL Server. My program consists of 2
Sorry for this not being a real question, but Sometime back i remember seeing

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.