The best way to add a concatenated string of multiple fields to a stored procedure
I have 14 datetime fields in my database. Ive been asked to return a single field of the 14 dates as one string field. Right now my stored proc looks kinda like this:
convert(varchar, [DTMON_F],108) as mondayFrom,
convert(varchar,[DTMON_T],108) as mondayTo,
convert(varchar,[DTTUES_F],108) as tuesdayFrom,
开发者_JAVA技巧 convert(varchar,[DTTUES_T],108) as tuesdayTo,
I want to have a single field called extendedDetails that is in the format HHmm - HHmm, HHmm - HHmm
This returns for example "10:20:00" so I'll have to somehow cut this to look like "1020" and then somehow concat all of them.
convert(varchar, [DTMON_F],108) as mondayFrom
SELECT
REPLACE
(
convert(char(5), [DTMON_F],108) + ' - ' +
convert(char(5),[DTMON_T],108) + ' - ' +
convert(char(5),[DTTUES_F],108) + ' - ' +
convert(char(5),[DTTUES_T],108) + ' - ' +
...
, ':', '') AS whatever
FROM MYTABLE
精彩评论