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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:41:42+00:00 2026-06-16T05:41:42+00:00

My sql query is select I.[Old Product Code], I.[Trade Name], I.[Short Name], SIL.[BOM Item

  • 0

My sql query is

select I.[Old Product Code], 
    I.[Trade Name], 
    I.[Short Name], 
    SIL.[BOM Item No_] ,
    CASE when SIL.[Dimension Group Code] = 'IOL' 
        then I.[Group Description] 
        else I.[Short Name] END as GD,
    CASE when SIL.[BOM Item No_] <> '' 
        then 'Kit' end
from [Sales Invoice Header] SIH, [Sales Invoice Line]  SIL, [Item] I 
where I.No_ =  SIL.No_ 
    and SIL.[Document No_] = 'PEXP1213-153' 
    and SIH.No_ = SIL.[Document No_] 
group by I.[Old Product Code], I.[Trade Name], I.[Short Name],  
    SIL.[Dimension Group Code], I.[Group Description], SIL.[BOM Item No_]

And my result is

current output

In this out of 21 rows i am having 17 rows as kit. I need to group this kit and to display in Old Product Code as Kit in one row instead of 17 rows.

  • 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-16T05:41:43+00:00Added an answer on June 16, 2026 at 5:41 am

    Looking at what you are trying to do you might be able to use something like this to return the data:

    ;with data as
    (
      select I.[Old Product Code], 
          I.[Trade Name], 
          I.[Short Name], 
          SIL.[BOM Item No_] ,
          CASE when SIL.[Dimension Group Code] = 'IOL' 
              then I.[Group Description] 
              else I.[Short Name] END as GD,
          CASE when SIL.[BOM Item No_] <> '' 
              then 'Kit' end CombinedKit
      from SalesInvoiceHeader SIH
      inner join SalesInvoiceLine  SIL
        on SIH.No_ = SIL.[Document No_] 
      inner join Item I 
        on I.No_ =  SIL.No_ 
      where SIL.[Document No_] = 'PEXP1213-153' 
    ),
    d2 as
    (
      select [Old Product Code],
        [Trade Name],
        [Short Name],
        [BOM Item No_],
        GD,
        CombinedKit,
        row_number() 
          over(partition by CombinedKit order by [Old Product Code]) rn
      from data
    ) 
    select 
        case when combinedkit = 'kit' 
            then 'Kit' else [Old Product Code] end  [Old Product Code],
        [Trade Name],
        [Short Name],
        [BOM Item No_],
        GD
        --, CombinedKit
    from d2
    where (CombinedKit = 'Kit' and rn = 1)
      or (CombinedKit is null) 
    

    See SQL Fiddle with Demo

    Edit, if you want to order this in a specific way you can use Order By with a CASE statement:

    ;with data as
    (
      select I.[Old Product Code], 
          I.[Trade Name], 
          I.[Short Name], 
          SIL.[BOM Item No_] ,
          CASE when SIL.[Dimension Group Code] = 'IOL' 
              then I.[Group Description] 
              else I.[Short Name] END as GD,
          CASE when SIL.[BOM Item No_] <> '' 
              then 'Kit' end CombinedKit
      from SalesInvoiceHeader SIH
      inner join SalesInvoiceLine  SIL
        on SIH.No_ = SIL.[Document No_] 
      inner join Item I 
        on I.No_ =  SIL.No_ 
      where SIL.[Document No_] = 'PEXP1213-153' 
    ),
    d2 as
    (
      select [Old Product Code],
        [Trade Name],
        [Short Name],
        [BOM Item No_],
        GD,
        CombinedKit,
        row_number() 
          over(partition by CombinedKit order by [Old Product Code]) rn
      from data
    ) 
    select 
        case when combinedkit = 'kit' 
            then 'Kit' else [Old Product Code] end  [Old Product Code],
        [Trade Name],
        [Short Name],
        [BOM Item No_],
        GD
        --, CombinedKit
    from d2
    where (CombinedKit = 'Kit' and rn = 1)
      or (CombinedKit is null) 
    order by 
      case when combinedkit = 'kit' then 0 else 1 end, [Old Product Code]
    

    See SQL Fiddle with Demo

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

Sidebar

Related Questions

i have this sql query select * from table where name like ? but
This is my SQL query: select name,description from wp_widget_custom where name in ('hemel-hempstead','maidenhead', 'guildford','bromley','east-london','hertfordshire','billericay','surrey')
I have this SQL query select case when AllowanceId is null then 2 else
When using this SQL query: Select * from table_name what happens if the name
SQL query: SELECT ArticleCategories.Title AS Category, Articles.Title, Articles.[Content], Articles.Date FROM ArticleCategories INNER JOIN Articles
I have the following SQL query: SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID, ra.BEZEICHNUNG
I have the following SQL query SELECT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID, ra.BEZEICHNUNG
i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
I have a simple SQL query: Select ID, COUNT(ID) as Selections, OptionName, SUM(Units) as
I have this sql query: SELECT S.SEARCH, S.STATUS, C.TITLE AS CategoryName, E.SEARCH_ENGINES AS Engine,

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.