0

I know there is a way to concatenate the values of a column using sql statement as it is explained here. For example

SELECT SUBSTRING(
        (SELECT ', '+ Name AS 'data()' from Names for xml path(''))
       ,3, 255) as "MyList"

Is it possible to make linq to sql generate the concatenation in the database as a subquery not in the memory or with many additional queries?

Community
  • 1
  • 1
Thea
  • 7,879
  • 6
  • 28
  • 40
  • possible duplicate of [Using Linq to concatenate strings](http://stackoverflow.com/questions/217805/using-linq-to-concatenate-strings) – Mitch Wheat Sep 03 '12 at 15:00
  • http://stackoverflow.com/questions/145856/how-to-join-int-to-a-character-separated-string-in-net – Mitch Wheat Sep 03 '12 at 15:01
  • a: there are simpler ways to concatenate - a `declare @s varchar(max) = '' select @s = @s+','+Name from Names select @s` is much simpler, and b: does `db.ExecuteQuery` count as an option? – Marc Gravell Sep 03 '12 at 15:37
  • Thansks @MitchWheat for the comments, but both of your suggestions make the concatenation in the memory. I want to make it on the SQL Server instead as this is part of a very heavy query and if I use Join() it make lots of separate queries. – Thea Sep 03 '12 at 15:39
  • @MarcGravell I asked how to make the LINQ TO SQL generate the query. I know that this is a easier way but if I am writing the query in T-SQL – Thea Sep 03 '12 at 15:40
  • To generate the query: not that I know of – Marc Gravell Sep 03 '12 at 15:43
  • Is their a particular reason to why you need it to be done in the DB rather than in code? – Magnus Sep 03 '12 at 15:49
  • cos in the code it makes more than 100 queries – Thea Sep 03 '12 at 21:45

0 Answers0