简体   繁体   English

SQL日期顺序

[英]SQL date order by

I have two kind of date format in my table now I want to show the date as order by. 我的表格中现在有两种日期格式,我想按日期显示日期。

The results look like this: 结果如下:

列值的屏幕截图

I want to display the records in ascending format in single format 我想以单一格式升序显示记录

Any help would be really appreciated 任何帮助将非常感激

In SQL Server, it is easiest to convert strings using the built in convert() formats. 在SQL Server中,最容易使用内置的convert()格式转换字符串。 This is a big inconvenience. 这是一个很大的不便。 You can try: 你可以试试:

order by coalesce(try_convert(datetime, meeting_status_date),
                  try_convert(datetime, meeting_status_date, 0),
                  try_convert(datetime, meeting_status_date, 101)
                 )

try_convert() returns NULL if the conversion fails. 如果转换失败, try_convert()返回NULL The list of conversion formats is here . 转换格式列表在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM