First of all sorry if i put the question in wrong section... :)
In sql server the following code adds varchar values separated by a comma sign and you can see the output in the image attached... [I found the code somewhere on the web]
Now my question is how do i perform this operation using C# LINQ queries when i have a datatable or a table in sql server and i want that kind of output.
In sql server the following code adds varchar values separated by a comma sign and you can see the output in the image attached... [I found the code somewhere on the web]
Code:
CREATE TABLE #YourTable ([ID] INT, [Name] CHAR(1))
INSERT INTO #YourTable ([ID],[Name]) VALUES (1,'A')
INSERT INTO #YourTable ([ID],[Name]) VALUES (1,'B')
INSERT INTO #YourTable ([ID],[Name]) VALUES (2,'C')
select * from #YourTable
SELECT
[ID]
, REPLACE(RTRIM((SELECT [Name] + ' ' FROM #YourTable WHERE (ID = Results.ID) FOR XML PATH (''))),' ',', ') AS NameValues
FROM #YourTable Results
GROUP BY ID
DROP TABLE #YourTable
Comment