Link to home
Start Free TrialLog in
Avatar of sanjshah12
sanjshah12Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Return a series of rows into one array

I am trying to return a series of rows into one array but this is for dates, the following works for text but not dates:


Declare @Datelist AS Nvarchar(MAX)
SELECT  @Datelist = COALESCE(@Datelist + ',', '') + [StartDate]
FROM   tbl_QuizDetails where StartDate IS NOT NULL

SELECT @Datelist

Open in new window


Am I able to convert the date to string or keep these as dates in the single string?

Any help is appreciated.

Regards
Avatar of Bill Prew
Bill Prew

This seems to work here, producing the output of:

01/01/2019,01/02/2019,01/03/2019

CREATE TABLE [tbl_QuizDetails](
	[StartDate] [datetime]
);

INSERT [tbl_QuizDetails] ([StartDate]) VALUES ('01/01/2019');
INSERT [tbl_QuizDetails] ([StartDate]) VALUES ('01/02/2019');
INSERT [tbl_QuizDetails] ([StartDate]) VALUES ('01/03/2019');

SELECT * FROM [tbl_QuizDetails];

Declare @Datelist AS Nvarchar(MAX)

SELECT  @Datelist = COALESCE(@Datelist + ',', '') + CONVERT(varchar, [StartDate], 101)
FROM   tbl_QuizDetails where StartDate IS NOT NULL

SELECT @Datelist

Open in new window


»bp
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sanjshah12

ASKER

Thanks Guys