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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:45:18+00:00 2026-05-13T10:45:18+00:00

I have orders and order details table as shown as below: OrderDetails Order_ID int

  • 0

I have orders and order details table as shown as below:

OrderDetails

Order_ID   int 
Order_Code varchar(10)
Product Name   varchar(50)
Qty     Int
SeqNO   varchar(10)

Below are the sample records

10001    OC   Ottoman   10  Null
10002    OC   Ottoman   3   Null  
10003    OC   Ottoman   2   Null
10004    OC   Ottoman   2   Null

Is there anyway I can update the SeqNo column with 1, 1A,1B,1C if the Order_Code is same else it should increment by one.

for example

10001    OC   Ottoman   10  Null
10002    OD   Ottoman   3   Null  
10003    OE   Ottoman   2   Null
10004    OF   Ottoman   2   Null

this one should be 1,2,3,4

Please help

  • 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-13T10:45:18+00:00Added an answer on May 13, 2026 at 10:45 am

    Not sure if I understand everything, but take a look at this example:

    DECLARE @OrderDetails TABLE
      ( 
       Order_ID int
      ,Order_Code varchar(10)
      ,Product_Name varchar(15)
      ,Qty int
      )
    
    INSERT  INTO @OrderDetails
            ( Order_ID, Order_Code, Product_Name, Qty)
    VALUES  ( 10001, 'OC', 'Ottoman', 10 )
    ,       ( 10002, 'OC', 'Ottoman', 3 )
    ,       ( 10003, 'OC', 'Ottoman', 2 )
    ,       ( 10004, 'OC', 'Ottoman', 2 )
    ,       ( 10005, 'SF', 'Sofa', 2 )
    ,       ( 10006, 'SF', 'Sofa', 7 )
    
    ;
    WITH  abcd
            AS ( SELECT Order_ID
                       ,Order_Code
                       ,Product_Name
                       ,Qty
                       ,DENSE_RANK() OVER ( ORDER BY Order_Code ) AS [RnkSeq]
                       ,ROW_NUMBER() OVER ( PARTITION BY Order_Code ORDER BY Order_ID ) AS [NumSeq]
                 FROM   @OrderDetails
               )
      SELECT  Order_ID
             ,Order_Code
             ,Product_Name
             ,Qty
             ,CAST(RnkSeq AS varchar(10)) + CHAR(64 + NumSeq) AS SeqNo
      FROM    abcd
    

    Returns

    Order_ID    Order_Code Product_Name    Qty         SeqNo
    ----------- ---------- --------------- ----------- -----------
    10001       OC         Ottoman         10          1A
    10002       OC         Ottoman         3           1B
    10003       OC         Ottoman         2           1C
    10004       OC         Ottoman         2           1D
    10005       SF         Sofa            2           2A
    10006       SF         Sofa            7           2B
    

    Hope this helps.

    UPDATE

    To update and have 1, 1A, 1B.. use:

    ;
    WITH  abcd
            AS ( SELECT Order_ID
                       ,Order_Code
                       ,Product_Name
                       ,Qty
                       ,DENSE_RANK() OVER ( ORDER BY Order_Code ) AS [RnkSeq]
                       ,ROW_NUMBER() OVER ( PARTITION BY Order_Code ORDER BY Order_ID ) AS [NumSeq]
                 FROM   @OrderDetails
               ),
          efgh
            AS ( SELECT Order_ID
                       ,Order_Code
                       ,Product_Name
                       ,Qty
                       ,CAST(RnkSeq AS varchar(10)) + CHAR(63 + NumSeq) AS [Seq]
                 FROM   abcd
               )
      UPDATE  @OrderDetails
      SET     SeqNo = REPLACE(e.Seq,'@','')
      FROM    @OrderDetails AS o
              JOIN efgh AS e ON e.Order_ID = o.Order_ID
    

    Beware what happens when you get more than 1, 1A, ... 1Z different order numbers for Ottomans.

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

Sidebar

Related Questions

I have a parent table, Orders and a child table, [Order Details], I have
I have a table: Order Detail. An Order has many details, in my case
I have a basic Customer/Order/OrderItem/Product object graph. Customer has Many Orders, Order has Many
In SQL Server 2005, I have an order details table with an order id
I have a orders table that have order detail and the column named Category
I have a Order Details table. What I want to do is create 1
Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:
I have 3 tables: Customers ID_CUSTOMER NAME Products ID_PRODUCT PRODUCTNAME PRICE Orders ID_ORDER CUSTOMER_ID
I have this code: var totalAmt=0; for (i in orders) { order=orders[i]; if (order.status
I need to display some details on DetailsView from two tables. I have table:

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.