10

I want to group by a table by some columns and show values of other column.in SQL v.2017 I can do that with string_agg function. but my SQL version is 2012.How can I do that...

create table dbo.TaskPeriods
(
 [id] [int] NULL,
 [startDate] [datetime] NULL,
 [endDate] [datetime] NULL
 )
 -------------------------------
insert into test.dbo.TaskPeriods values(1,'2018-07-24 00:00:00.000','2018-07-24 10:00:00.000')
insert into test.dbo.TaskPeriods values(2,'2018-07-24 00:00:00.000','2018-07-24 10:00:00.000')
insert into test.dbo.TaskPeriods values(3,'2018-07-24 08:00:00.000','2018-07-24 12:00:00.000')
 --------------------------------------------------------
select id,startDate,endDate from  test.dbo.TaskPeriods
 --------------------------------------------------------
select 
min (startDate)
,max (endDate)
--,string_agg(id,',')  //How to Do this Without string_agg Function
FROM test.dbo.TaskPeriods
group by startDate,endDate

Is there any way to concat one particular column against another group of columns in SQL Server 12.0?

Auspex
  • 2,175
  • 15
  • 35
mohammadrg
  • 151
  • 1
  • 8
  • SQL is a language, implemented by many products (of which MS SQL Server is one.) – jarlh Jun 13 '19 at 07:10
  • 2
    Yes, but each implementation differs slightly from each other. STRING_AGG() does not exist in older versions of MS SQL Server and that was the problem here. – Sam Mar 04 '20 at 16:47

0 Answers0