Tuesday, May 5, 2015

Is this possible or practical?

Yes, it is possible ,see an example below

CREATE  TABLE  #mable(mid INT, token nvarchar(16))

INSERT INTO #mable VALUES (0, 'foo')
INSERT INTO #mable VALUES(0, 'goo')
INSERT INTO #mable VALUES(1, 'hoo')
INSERT INTO #mable VALUES(1, 'moo')

SELECT m1.mid,
       ( SELECT m2.token + ','
           FROM #mable m2
          WHERE m2.mid = m1.mid
          ORDER BY token
            FOR XML PATH('') ) AS token
  FROM #mable m1

Best Regards,Uri Dimant SQL Server MVP, http://ift.tt/1iQ9JkR

MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting: Large scale of database and data cleansing
Remote DBA Services: Improves MS SQL Database Performance
SQL Server Integration Services: Business Intelligence

No comments:

Post a Comment