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?

2
  • SQL is a language, implemented by many products (of which MS SQL Server is one.) Commented Jun 13, 2019 at 7: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. Commented Mar 4, 2020 at 16:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.