views:

36

answers:

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

+1  A: 

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
AdaTheDev
Thank you very much, that i want.
Om