Click here to Skip to main content
14,580,625 members
Rate this:
Please Sign up or sign in to vote.
I work on SQL server 2012 I face Issue : I can't arrange Features contain Unit as second Item display for same Display Order .

for feature family as example

'Family' as [Family], 'FamilyMaxValue' as [FamilyMaxValue], 'FamilyUnit' as [FamilyUnit]

I need it to be as below

'Family' as [Family], 'FamilyUnit' as [FamilyUnit],'FamilyMaxValue' as [FamilyMaxValue]

Feature and Unit and max value get same Display Order for every Feature but my issue

How to get Unit as Second Display for same Display Order .

Meaning change will be Order of items separated by comma to display feature Unit as second display for same Display Order.

create table #SplitNumberAndUnitsFinal
DKFeatureName  nvarchar(100),
DisplayOrder  int
insert into #SplitNumberAndUnitsFinal (DKFeatureName,DisplayOrder)

Expected Result arrange feature Unit as second display to be as:

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]

AND I don't Need to Display it as below :

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]

What I have tried:

DECLARE @Header nvarchar(max)=( select
        Select  ', '''+ DKFeatureName +''' as ['+ DKFeatureName +']' AS [text()]
        From #SplitNumberAndUnitsFinal 
        GROUP BY DKFeatureName
        ORDER BY MIN(DisplayOrder)
        For XML PATH ('')
    ), 2, 10000) [Columns])
    print @Header
Updated 28-Jun-20 1:34am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100