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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:58:39+00:00 2026-05-26T18:58:39+00:00

So, I figure I could probably come up with some wacky solution, but i

  • 0

So, I figure I could probably come up with some wacky solution, but i figure i might as well ask up front.

each user can have many orders.
each desk can have many orders.
each order has maximum 3 items in it.

trying to set things up so a user can create an order and the order auto generates a reference number and each item has a reference letter. reference number is 0-99 and loops back around to 0 once it hits 99, so orders throughout the day are easy to reference for the desks.

So, user places an order for desk #2 of 3 items:
78A: red stapler
78B: pencils
78C: a kangaroo foot

not sure if this would be done in the program logic or done at the SQL level somehow.

was thinking something like neworder = order.last + 1 and somehow tying that into a range on order create. pretty fuzzy on specifics.

  • 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-26T18:58:39+00:00Added an answer on May 26, 2026 at 6:58 pm

    Without knowing the answer to my comment above, I will assume you want to have the full audit stored, rather than wiping historic records; as such the 78A 78B 78C type orders are just a display format.

    If you have a single Order table (containing your OrderId, UserId, DeskId, times and any other top-level stuff) and an OrderItem table (containing your OrderItemId, OrderId, LineItemId — showing 1,2 or 3 for your first and optional second and third line items in the order, and ProductId) and a Product table (ProductId, Name, Description)

    then this is quite simple (thankfully) using the modulo operator, which gives the remainder of a division, allowing you in this case to count in groups of 3 and 100 (or any other number you wish).
    Just do something like the following:
    (you will want to join the items into a single column, I have just kept them distinct so that you can see how they work)
    Obviously join/query/filter on user, desk and product tables as appropriate

    select
    o.OrderId,
    o.UserId,
    o.DeskId
    o.OrderId%100 + 1 as OrderNumber, 
    case when LineItem%3 = 1 then 'A'
     when LineItem%3 = 2 then 'B'
     when LineItem%3 = 0 then 'C'
    end as ItemLetter,
    oi.ProductId
    from tb_Order o inner join tb_OrderItem oi on o.OrderId=oi.OrderId
    

    Alternatively, you can add the itemLetter (A,B,C) and/or the OrderNumber (1-100) as computed (and persisted) columns on the tables themselves, so that they are calculated once when inserted, rather than recalculating/formatting when they are selected.
    This sort-of breaks some best practice that you store the raw data in the DB and you format on retrieval; but if you are not going to update the data and you are going to select the data for more than you are going to write the data; then I would break this rule and calculate your formatting at insert time

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

Sidebar

Related Questions

well i have most probably an extremly stupid problem but could not figure it
this might question might sounds stupid, but I could'nt figure it out. How can
Probably simple but could not figure out. I am loading an assembly at runtime
This is probably a simple question, but I can't figure it out. I would
it looks very basic thing but i could not figure it out. var email
I see this in Facebook (also Google), but can't figure out how to do
I'm not seeing the error and was hoping someone could figure it out: public
i just could not figure out how i will put my data on a
I'm trying to play with inter-process communication and since I could not figure out
I am looking at the query syntax . and i could not figure out

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.