SQL Server Extract Minimum date

t98cgbkg  于 2023-02-28  发布在  其他
关注(0)|答案(1)|浏览(111)

I have column Date where some cells have one date, some two or more.

From multiple dates in one cell of the Date column I want to extract minimum date or if it one date then retain the date.

Could someone please help me. Below is the sample.

koaltpgm

koaltpgm1#

You could try to use STRING_SPLIT function

SELECT Date, MIN(s.value) AS Min_Date
FROM <your table> d 
     CROSS APPLY STRING_SPLIT(d.Date, '|') AS s
GROUP BY Date;

See demo here .

相关问题