Get comma separated list in SQL and MDX.

To get comma separated list in SQL as well as in MDX use below queries.

1 – SQL

Select Name from Sales.SalesReason

GO

Select Name from Sales.SalesReason

SELECT

SUBSTRING

(

(

SELECT

‘,’ + s.Name

FROM

Sales.SalesReason  s

ORDER BY

s.Name

FOR XML PATH(”)

)

,2,200000 ) AS NAME

1_SQL_Server_Get_a_comma_separated_list_in_SQL_MDX.

2 – MDX

WITH

SET [COMMA] AS [Sales Reason].[Sales Reasons].[Sales Reason].MEMBERS

MEMBER [MEASURES].[COMMATEST] AS

Generate

(

[COMMA]

,[COMMA].CurrentMember.Name

,”,”

)

SELECT

NON EMPTY

{

[MEASURES].[COMMATEST]

} ON 0

FROM

[ADVENTURE WORKS];

2_SQL_Server_Get_a_comma_separated_list_in_SQL_MDX

 

Regards

Suhas Kudekar

Like us on FaceBook Follow us on Twitter | Join the fastest growing SQL Server group on FaceBook

Follow me on TwitterFollow me on FaceBook

 
Data Platform Virtual Summit 2020

Subscribe to SQLServerGeeks YouTube channel. If you want more learning content in your inbox, subscribe to SQLServerGeeks Bulletin.

SQLServerGeeks YouTube | SQLServerGeeks Bulletin | SQLServerGeeks Twitter

One Comment on “Get comma separated list in SQL and MDX.”

Leave a Reply

Your email address will not be published. Required fields are marked *