Author |
Topic |
Vivan
Starting Member
9 Posts |
Posted - 2015-04-19 : 12:49:02
|
Please help me to solve this puzzleDECLARE @MYTABLE TABLE([Part Type] VARCHAR (50),[Desc 1] VARCHAR (50), [Desc 2] VARCHAR (50), [Desc 3] VARCHAR (50),[Desc 4] VARCHAR (50), [Desc 5] VARCHAR (50))INSERT @MYTABLESELECT 'Nerf Bar', 'Step Type', 'Finish', 'Color', 'Material', 'Type' UNION ALLSELECT 'Nerf Bar', 'Step Type', 'Finish', 'Color', 'Material', 'Type' UNION ALLSELECT 'Nerf Bar', 'Step Type', 'Finish', 'Color', 'Material', 'Type' UNION ALLSELECT 'Nerf Bar', 'Step Type', 'Finish', 'Color', '', 'Type' UNION ALLSELECT 'Nerf Bar', 'Step Type', 'Start' , 'Color', 'Material', 'Type' UNION ALLSELECT 'Shifter Boot', 'Compatibility', 'Diameter (IN)', 'Base Length (IN)', 'Base Width (IN)','Color' UNION ALLSELECT 'Shifter Boot', 'Compatibility', 'Diameter (IN)', 'Base Length (IN)' ,'Base Width (IN)', 'Color' UNION ALLSELECT 'Shifter Boot', 'Not Compatible', 'Diameter (IN)', 'Base Length (IN)', 'Base Width (IN)', 'Color' UNION ALLSELECT 'Shifter Boot', 'Compatibility', 'Diameter (IN)', 'Base Length UK', 'Base Width (IN)', 'Color' UNION ALLSELECT 'Tail Light', 'Used', 'Lens Color', 'Reflector', 'With Seal' ,'Hardware' UNION ALLSELECT 'ACCELATOR', 'Compatibility' ,'Base Diameter (IN)', 'Base Length (IN)', 'Base Width (IN)', 'Color' UNION ALLSELECT 'ACCELATOR', 'Compatibility', 'Base Diameter (IN)', 'Base Length (IN)' ,'Base Width (IN)', 'Color'SELECT * FROM @MYTABLE/*I am trying to get solution for this complicated Scenerio, for a given Part Type we have DESC 1 TO DESC 51st: I need to check There will be always More Than 1 part type , SO In this case Nerf Bar and Shifter Boot are the two Part Type which Occurred More Than 1 timeTail Light Part Type is occurred only once, so ignore2nd: I need to check For a Given Part Type there will be same value contain in desc 1 to desc 5 across rowsif any changes or mismatch then it should appear in OutputFor Part Type Accelator from desc 1 to desc 5 same records for both rows so ignored.Output Look Like 'Nerf Bar', 'Step Type', 'Finish', 'Color', 'Material', 'Type' 'Nerf Bar', 'Step Type', 'Finish', 'Color', '', 'Type' 'Nerf Bar', 'Step Type', 'Start' , 'Color', 'Material', 'Type' 'Shifter Boot', 'Compatibility', 'Diameter (IN)', 'Base Length (IN)' ,'Base Width (IN)', 'Color' 'Shifter Boot', 'Not Compatible', 'Diameter (IN)', 'Base Length (IN)', 'Base Width (IN)', 'Color''Shifter Boot', 'Compatibility', 'Diameter (IN)', 'Base Length UK', 'Base Width (IN)', 'Color' */viva |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2015-04-19 : 13:30:05
|
[code]-- SwePesoWITH cteDataAS ( SELECT [Part Type], [Desc 1], [Desc 2], [Desc 3], [Desc 4], [Desc 5], COUNT(*) OVER (PARTITION BY [Part Type]) AS rn FROM ( SELECT DISTINCT [Part Type], [Desc 1], [Desc 2], [Desc 3], [Desc 4], [Desc 5] FROM @MyTable ) AS x)SELECT [Part Type], [Desc 1], [Desc 2], [Desc 3], [Desc 4], [Desc 5]FROM cteDataWHERE rn >= 2;[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|