我在SQLServer2012上工作,我面临一个问题:我不能将包含单元的功能安排为同一显示顺序的第二项显示。
以特征族为例
'Family' as [Family], 'FamilyMaxValue' as [FamilyMaxValue], 'FamilyUnit' as [FamilyUnit]
我需要它如下
'Family' as [Family], 'FamilyUnit' as [FamilyUnit],'FamilyMaxValue' as [FamilyMaxValue]
功能和单位和最大值得到相同的显示顺序,但我的问题
如何获得单位作为第二显示相同的显示顺序。
意思改变将是以逗号分隔的项目顺序,以显示特征单元作为同一显示顺序的第二个显示。
create table #SplitNumberAndUnitsFinal
(
DKFeatureName nvarchar(100),
DisplayOrder int
)
insert into #SplitNumberAndUnitsFinal (DKFeatureName,DisplayOrder)
values
('package',1),
('packageUnit',1),
('Family',2),
('FamilyMaxValue',2),
('FamilyUnit',2),
('parts',3),
('partsMaxValue',3),
('partsUnit',3)
DECLARE @Header nvarchar(max)=( select
substring(
(
Select ', '''+ DKFeatureName +''' as ['+ DKFeatureName +']' AS [text()]
From #SplitNumberAndUnitsFinal
GROUP BY DKFeatureName
ORDER BY MIN(DisplayOrder)
--order by DisplayOrder
For XML PATH ('')
), 2, 10000) [Columns])
print @Header
预期结果将特征单元排列为第二个显示,如下所示:
Feature,FeatureUnit,FeatureMaxValue according to same display Order
'package' as [package], 'packageUnit' as [packageUnit],
'Family' as [Family], 'FamilyUnit' as [FamilyUnit],'FamilyMaxValue' as [FamilyMaxValue],
'parts' as [parts], 'partsUnit' as [partsUnit],'partsMaxValue' as [partsMaxValue]
我不需要显示如下:
Feature,FeatureMaxValue,FeatureUnit for same Display Order
'package' as [package], 'packageUnit' as [packageUnit],
'Family' as [Family], 'FamilyMaxValue' as [FamilyMaxValue], 'FamilyUnit' as [FamilyUnit],
'parts' as [parts], 'partsMaxValue' as [partsMaxValue], 'partsUnit' as [partsUnit]
1条答案
按热度按时间lo8azlld1#
如果需要,则需要一个附加列来控制显示顺序
DisplayOrder
孤独不是唯一的。这将允许您在ORDER BY
所需订单的条款: