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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:50:35+00:00 2026-06-09T22:50:35+00:00

Problem I import a spread sheet that contains parent group data on the same

  • 0

Problem

I import a spread sheet that contains parent group data on the same column as the child. I would like to add extract column for group as show below.

Create Table

DECLARE @Fruit TABLE
    (
      ProductID INT IDENTITY(1, 1)
                    PRIMARY KEY ,
      FruitName NVARCHAR(20) ,
      FruitCost MONEY
    )

INSERT  INTO @fruit
        ( FruitName, FruitCost )
VALUES  ( 'Berry', NULL )
INSERT  INTO @fruit
        ( FruitName, FruitCost )
VALUES  ( 'BlueBerry', 2 )
INSERT  INTO @fruit
        ( FruitName, FruitCost )
VALUES  ( 'StrawBerry', 2 )
INSERT  INTO @fruit
        ( FruitName, FruitCost )
VALUES  ( 'Citrus', NULL )
INSERT  INTO @fruit
        ( FruitName, FruitCost )
VALUES  ( 'Lemon', 2 )
INSERT  INTO @fruit
        ( FruitName, FruitCost )
VALUES  ( 'Orange', 2 )

SELECT  *
FROM    @Fruit

Table Results

ProductID   FruitName            FruitCost
----------- -------------------- ---------------------
1           Berry                NULL
2           BlueBerry            2.00
3           StrawBerry           2.00
4           Citrus               NULL
5           Lemon                2.00
6           Orange               2.00

Required Results

FruitName            FruitCost             FruitGroup
-------------------- --------------------- --------------------
BlueBerry            2.00                  Berry
StrawBerry           2.00                  Berry
Lemon                2.00                  Citrus
Orange               2.00                  Citrus
  • 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-09T22:50:37+00:00Added an answer on June 9, 2026 at 10:50 pm

    Try this

    select
        f3.FruitName, f3.FruitCost, f.FruitName
    from
        @Fruit f
            inner join
        (
            SELECT  *,
            (Select max(productid) from @Fruit f2 where FruitCost is null and ProductID<=f.ProductID) as fgroup
            FROM    @Fruit f
        ) f3
            on f.ProductID = f3.fgroup
    where f3.FruitCost is not null  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a small program showing a problem: import Data.Fixed main = do print
The problem is during inserting data from staging table during import routine. The system
I have a problem using the SSIS. I try to import data from database
I have a problem with import of a 3D model into a WebGL shader
I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
I have a problem with 2D transformation program I have the source code import
I'm working with intelliJ and my problem is when I start to import some
I have a problem with Observer-Pattern and deadlock using threads. package observerDeadLock; import java.util.Observable;
I have a txt file that I’m trying to import as flat file into
Background I have a spreadsheet of data that I'm importing into SQL Server 2005.

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.