Questions tagged [sql-server-group-concat]

In MySQL GROUP_CONCAT functionality is comma separated values grouped by a defined key.

In MySQL GROUP_CONCAT functionality is comma separated values grouped by a defined key.

62 questions
482
votes
23 answers

How to use GROUP BY to concatenate strings in SQL Server?

How do I get: id Name Value 1 A 4 1 B 8 2 C 9 to id Column 1 A:4, B:8 2 C:9
Eldila
  • 15,426
  • 23
  • 58
  • 62
135
votes
4 answers

How to make a query with group_concat in sql server

I know that in sql server we cannot use Group_concat function but here is one issue i have in which i need to Group_Concat my query.I google it found some logic but not able to correct it.My sql query is select …
Rahul
  • 5,603
  • 6
  • 34
  • 57
107
votes
1 answer

Multiple rows to one comma-separated value in Sql Server

I want to create a table valued function in SQL Server, which I want to return data in comma separated values. For example table: tbl ID | Value ---+------- 1 | 100 1 | 200 1 | 300 1 | 400 Now when I execute the query using the function…
Sanjeev Singh
  • 3,976
  • 3
  • 33
  • 38
46
votes
7 answers

SQL, How to Concatenate results?

I currently have a SQL query that returns a number of fields. I need one f the fields to be effectively a sub query sub that. The Problem in detail: If I have a table X with two columns, ModuleID and say ModuleValue, how can I write a SQL query to…
23
votes
3 answers

SQL Query to get aggregated result in comma separators along with group by column in SQL Server

I need to write a sql query on the table such that the result would have the group by column along with the aggregated column with comma separators. My table would be in the below format |`````````|````````| | ID | Value | …
21
votes
4 answers

How to concatenate all strings from a certain column for each group

Suppose I have this table [Table1] Name Mark ------- ------ ABC 10 DEF 10 GHI 10 JKL 20 MNO 20 PQR 30 What should be my SQL statement to retrieve a record that looks like this: (group by [mark]). I have done the 1 and 2…
yonan2236
  • 13,371
  • 33
  • 95
  • 141
15
votes
4 answers

SQL comma-separated row with Group By clause

I have the following query: SELECT Account, Unit, SUM(state_fee), Code FROM tblMta WHERE MTA.Id = '123' GROUP BY Account,Unit This of course throws an exception because the Code is not in the group by clause. Each state_fee has a code. How…
8
votes
3 answers

How to execute a query which is stored in a table column MySQL?

mysql> select * from CT; | CID | MID | REPORT_QUERY | | 1 | 1 | select * from emp; | | 2 | 2 | select * from student; | 2 rows in set (0.00 sec) I want to execute queries in REPORT_QUERY column. DELIMITER // CREATE…
7
votes
3 answers

string concatenate in group by function with other aggregate functions

Is it possible to concatenate strings with one or more of other group by function like sum, avg, count etc . Say I have the following table Id Name Order Value 1 a 1 100 2 b 2 200 3 c 1 300 4 d 1 100 5 e …
6
votes
1 answer

How to use GROUP BY to concatenate strings while joining multiple tables?

I'm joining multiple tables in which I want one column value into row according to TechnicianName: I have 4 tables easy_tbljobcard , easy_tbltechnician and easy_tblproblem and easy_tbltechnicianMaster I am getting TechnicianName in 2nd column from…
5
votes
1 answer

group_concat in SQL Server 2012 with ORDER BY another column

I have a table containing ~ a million entries like this: customer_id | purchased_at | product 1 | 2012-06-01 00:00 | apples 1 | 2012-09-02 00:00 | apples 1 | 2012-10-01 00:00 | pears 2 | 2012-06-01 00:00 |…
AGS
  • 51
  • 1
  • 2
4
votes
4 answers

SQL same unit between two tables needs order numbers in 1 cell

I have 2 tables: SELECT UnitId FROM dbo.tblUnits SELECT UnitId, WorkOrderNumber FROM dbo.tblWorkOrders I need to display all UnitId's from dbo.tblUnits then in 1 column diplay all the WorkOrders seperated by a comma. So here is some sample…
user380432
  • 4,619
  • 16
  • 51
  • 62
4
votes
1 answer

group_concat was cut when running a query on table

I have a table that looks likes this: and this table contains 343 rows. I'm trying to run this query on it: create table newTest2 select function_name, service_name, min(concurrency), substring_index(group_concat(date order by concurrency ),…
tkyass
  • 2,968
  • 8
  • 38
  • 57
4
votes
3 answers

SQL Server Group Concat with Different characters

I have looked through a number of solutions to emulating "Group concat" functionality in SQL Server. I wanted to make a more human readable solution though and I can't work out how to do it. I have a view: ParentID | ChildName Which contains the…
Molloch
  • 2,261
  • 4
  • 29
  • 48
3
votes
2 answers

Tricky T-SQL Query. Concatenate multiple values from a column between master/child tables

I have three tables as follows: MasterTable +----------+-------------+ | MasterId | MasterName | +----------+-------------+ | 1 | Master 1 | | 2 | Master 2 | | 3 | Master 3 | | 4 | Master 4 …
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
1
2 3 4 5