sql-server-group-concat

GROUP_CONCAT in SQL Server error

扶醉桌前 提交于 2020-01-16 09:06:08
问题 Error:Column 'ReviewConsultants.ConsultantID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Query: select R.ReviewID, STUFF((select distinct ',' + FirstName from Users where UserID = RC.ConsultantID FOR XML PATH ('')), 1, 1, '') AS consultantlist from [Reviews] R, [ReviewConsultants] RC where R.ReviewID = RC.ReviewID group by R.ReviewID; One review can have one or more consultants.I am trying to get the consultants for each

SQL CONCAT IF Statement?

老子叫甜甜 提交于 2020-01-05 07:03:46
问题 Morning All, Im not to sure how i need to solve my following query... I have the following query which pulls back the desired records in SQL server... SELECT agenda.AgendaItemNumber,Agenda.AgendaName, AgendaType.AgendaTypeDescription, userdetails.fullName FROM Agenda JOIN AgendaType ON AgendaType.AgendaTypeID=Agenda.AgendaTypeID JOIN UserDetails ON Agenda.AgendaID = Userdetails.AgendaID WHERE agenda.AgendaTypeID = '2' AND AgendaItemNumber = AgendaItemNumber AND AgendaName = AgendaName AND

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

自古美人都是妖i 提交于 2020-01-01 06:35:25
问题 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 PROCEDURE TRYct() BEGIN SET @str=(SELECT GROUP_CONCAT(REPORT_QUERY SEPARATOR ' ') FROM CT); PREPARE q from @str; EXECUTE q; END // DELIMITER ; i use this code but it works if there is only one query in my table. if there is two query than it gives an error. ERROR 1064 (42000): You

Concatenate one field after GROUP BY

狂风中的少年 提交于 2019-12-17 16:31:30
问题 This question have been asked many times in SO but none of the answers is satisfying to my situation. Question 1 Question 2 Question 3 Question 4 I am dealing with a DataObjectVersions table that contains multiple versions for around 1.2 million unique objects (and increasing). I need to concatenate changes from a specific field for each unique object. Right now I am using the solution with the XML Path presented in Q3 but running such a query on this table is a total performance disaster.

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

馋奶兔 提交于 2019-12-17 14:54:00
问题 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 data: dbo.tblUnits: UnitId 123 156 178 dbo.tblWorkOrders UnitId WorkOrderNumber 123 1 123 2 156 4 178 5 178 9 178 10 I have to use the tblUnits table because I am pulling more data from it but the final result I want to show this: UnitId WorkOrderNumber 123

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

假如想象 提交于 2019-12-17 14:53:46
问题 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 data: dbo.tblUnits: UnitId 123 156 178 dbo.tblWorkOrders UnitId WorkOrderNumber 123 1 123 2 156 4 178 5 178 9 178 10 I have to use the tblUnits table because I am pulling more data from it but the final result I want to show this: UnitId WorkOrderNumber 123

Multiple rows to one comma-separated value [duplicate]

老子叫甜甜 提交于 2019-12-17 02:08:10
问题 This question already has answers here : How to concatenate text from multiple rows into a single text string in SQL server? (47 answers) How to create a SQL Server function to “join” multiple rows from a subquery into a single delimited field? [duplicate] (13 answers) Closed 5 years ago . 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

group_concat was cut when running a query on table

≯℡__Kan透↙ 提交于 2019-12-06 09:22:04
问题 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 ), ',',1) as minDate, max(concurrency), substring_index(group_concat(date order by concurrency desc), ',',1) as maxDate , avg(concurrency) from conc_intermidate group by function_name,service_name; and when I run the query it gives me the : "row 203 was cut

group_concat was cut when running a query on table

自作多情 提交于 2019-12-04 13:39:11
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 ), ',',1) as minDate, max(concurrency), substring_index(group_concat(date order by concurrency desc), ',',1) as maxDate , avg(concurrency) from conc_intermidate group by function_name,service_name; and when I run the query it gives me the : "row 203 was cut by GROUP_CONCAT()", I don't know why it's giving me this error. Please HELP! thanks... tkyass Thanks to

Group and concatenate many rows to one

我们两清 提交于 2019-12-04 05:29:37
问题 I want to "concatenate" all the "Text"-rows into one single row and get one row as a result. Is this even possible? I use MSSQL Server 2005. 回答1: Use FOR XML PATH: SELECT [Text]+' ' AS 'text()' FROM _table FOR XML PATH('') Another option - use string concatenation: DECLARE @s nvarchar(max) SELECT @s = ISNULL(@s, '') + t + ' ' FROM _table OPTION (MAXDOP 1) SELECT @s Please note that the latter one isn't guaranteed to work, afaik, officially the behaviour of "@s = @s + ..." for multi-row