Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:04:23+00:00 2026-06-11T23:04:23+00:00

I have a generic Dimension and DimensionMember tables. CREATE TABLE [dbo].[Dimension] ( [ID] [int]

  • 0

I have a generic “Dimension” and “DimensionMember” tables.

CREATE TABLE [dbo].[Dimension]
(
    [ID] [int] NOT NULL IDENTITY(1, 1),
    [Label] [nvarchar] (255)
) 

CREATE TABLE [dbo].[DimensionMember]
(
[ID] [int] NOT NULL IDENTITY(1, 1),
[Label] [nvarchar] (255) NOT NULL,
[DimensionID] [int] NOT NULL
) 
GO
ALTER TABLE [dbo].[DimensionMember] ADD CONSTRAINT [FK_DimensionMember_DimensionID_Dimension_ID] FOREIGN KEY ([DimensionID]) REFERENCES [dbo].[Dimension] ([ID])

These table store a large number of dimensions and dimension members.

I want to cross join dimension members from variable number of dimensions.
Example: cross join dimension members from ‘Sex’,’Employment Type’,’Contract Type’ dimension should produce the following combinations

'Male,Full time, Employee'
'Female,Full time, Employee'
'Male,Part time, Employee'
'Female,Part time, Employee'

'Male,Full time, Contractor'
'Female,Full time, Contractor'
'Male,Part time, Contractor'
'Female,Part time, Contractor'

The labels of the combinations should be created by concatenating labels of dimension members (as shown above).

Thank you in advance

UPDATE

A list of dimension (e.g. ‘Sex’,’Employment Type’,’Contract Type’) is DYNAMIC (produced by another query at run-time).

UPDATE 2

Fixed a small error (Dimension1 -> Dimension). Sorry!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:04:25+00:00Added an answer on June 11, 2026 at 11:04 pm

    How about this pattern? (SQL Fiddle)

    select a.label+','+b.label+','+c.label
    from (select m.label from dimension1 d
      join dimensionmember m
          on m.dimensionid = d.id and d.label = 'sex') a
    cross join (select m.label from dimension1 d
      join dimensionmember m 
          on m.dimensionid = d.id and d.label = 'Employment Type') b
    cross join (select m.label from dimension1 d
      join dimensionmember m 
          on m.dimensionid = d.id and d.label = 'Contract Type') c
    

    Granted you need to know how many subqueries to build and therefore how long the concatenation part in the SELECT needs to be.


    EDIT

    And here’s one that does it all (updated SQL Fiddle)

    ;with base as (
       select m.label, d.id, dense_rank() over (order by d.id) rk
         from dimension1 d
         join dimensionmember m
           on m.dimensionid = d.id
        where d.label in ('sex','Employment Type','Contract Type')
    ), cte as (
       select cast(label as varchar(max)) list, rk
         from base
        where rk=1
    union all
       select cast(cte.list+','+base.label as varchar(max)), base.rk
         from cte
         join base on base.rk=cte.rk+1
    )
       select list
         from cte
        where rk=(select max(rk) from base)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any name for the following DB table design: Basically we have generic
I have a Generic List object which hold below table as its own value.
We have a normalized SQL Server 2008 database designed using generic tables. So, instead
I was wondering why I can not have generic property in non-generic class the
I have generic list which must be a preserved order so I can retrieve
I have generic type that looks like: public class GenericClass<T, U> where T :
I want to write in Delphi (2009 - so I have generic dictionary class)
I am aware of Web Services and WCF but I have generic question with
I have a generic linked-list that holds data of type void* I am trying
I have a Generic Base Class that I want to allow one of two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.