开发者

SQL query for dynamic insert row

I am having data like:

开发者_JS百科
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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜