I need consolidate columns from a table. I have a table will 3 group id and attribute id columns. I need to create a separate record for each group of attribute groups and attribute ids. Basically, i need a table with just one column for the attribute group and ID.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
SELECT a.RecID, ca1.GroupID, ca1.AttributeID FROM dbo.table_A a CROSS APPLY ( SELECT * FROM ( VALUES (1,GroupID,AttributeID), (2,GroupID1,AttributeID1), (3,GroupID2,AttributeID2) ) AS x(Group#,GroupID, AttributeID) WHERE x.GroupID <> '' ) AS ca1 ORDER BY RecID, Group#
slightwv (䄆 Netminder)
Is this not the same basic question you had before?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
slightwv (䄆 Netminder)
>>
In your case, you want to unpivot the columns into rows
SELECT a.RecID, ca1.GroupID, ca1.AttributeID
FROM dbo.table_A a
CROSS APPLY (
SELECT * FROM (
VALUES (1,GroupID,AttributeID), (2,GroupID1,AttributeID1), (3,GroupID2,AttributeID2)
) AS x(Group#,GroupID, AttributeID)
WHERE x.GroupID <> ''
) AS ca1
ORDER BY RecID, Group#