Skip to content Skip to sidebar Skip to footer

How To Stuff Date And Time In Sql

i am having trouble stuffing the date and time for the same item in SQL sever. Below are three simple records. Date_Time ID 9/6/2018 5:36:30 PM 12345 9/6/2018 6

Solution 1:

If you are using sql server 2017 or above you can use string_agg as below:

select id, string_agg(convert(varchar,DATE_Time, 22), ', ')
    from#YourTable groupby id

If it is below sql server 2017 you can use below query:

select id, stuff ((
    select', ' + convert(nvarchar, date_time, 22) from#Table2 where id = t.idfor xml path('')
    ),1,2,'') as dates
from #Table2 t
groupby id

Solution 2:

On MySQL

SELECT id, group_concat(Date_Time) as test FROM TABLE_NAME GROUP BY ID

Post a Comment for "How To Stuff Date And Time In Sql"