1

I am having data like:

ItemCode          Attribute      PositionID   
ITEM-000032 CHESTSIZE   1
ITEM-000032 JACKETLEN            2
ITEM-000042 CHESTSIZE            1
ITEM-000042 JACKETLEN            2
**ITEM-000049   SLACKWAIST  1**
ITEM-000071 CHESTSIZE            1
ITEM-000071 JACKETLEN            2
ITEM-000074 CHESTSIZE            1
ITEM-000074 JACKETLEN            2

In above data except ITEM-000049 others are having perfect combination. so i want to create a new row for ITEM-000049 As

ITEM-000049 --  2

to make it perfect.

Kind regards, Om

4
  • Why don't you just insert the new row? Commented Feb 3, 2010 at 10:30
  • You need to make it clearer what you want - "a perfect combination" makes no sense Commented Feb 3, 2010 at 10:30
  • 1
    After adding the row ITEM-000049 -- 2 Output will like below: ItemCode Attribute PositionID ITEM-000032 CHESTSIZE 1 ITEM-000032 JACKETLEN 2 ITEM-000042 CHESTSIZE 1 ITEM-000042 JACKETLEN 2 ITEM-000049 SLACKWAIST 1 ITEM-000049 -- 1 ITEM-000071 CHESTSIZE 1 ITEM-000071 JACKETLEN 2 ITEM-000074 CHESTSIZE 1 ITEM-000074 JACKETLEN 2 Commented Feb 3, 2010 at 10:40
  • They are having positionID 1 & 2 except the ITEM-000049, so i want to add one row with PositionID = 2 & Attribute = -- for the same ItemCode. Is that make sense? Commented Feb 3, 2010 at 10:44

1 Answer 1

1

Sounds like for each ItemCode, you are expecting 2 records, for 2 different Attributes.

So something like this is what I think you're after. Just run the SELECT part of it first without the INSERT to check it is indeed what you're after.

INSERT YourTable (ItemCode, Attribute, PositionID)
SELECT t.ItemCode, 'SECOND ATTRIBUTE', 2
FROM 
(
SELECT ItemCode
FROM YourTable
GROUP BY ItemCode
HAVING COUNT(*) = 1
) t
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.