1

我有大约 5 个工会的询问;最后,我在 DateTime 字段上得到了一个订单(所以我 100% 肯定不是在 varchar 上订购)——而且似乎由于某种原因订单被搞砸了,有什么想法吗?也没有可识别的模式:(

SELECT a, b, c, DateField
FROM whatever

UNION

SELECT a, b, c, DateField
FROM whatever

UNION

SELECT a, b, c, DateField
FROM whatever

Order By convert(DateTime, DateField, 111) -- The convert is just to make doubly sure about the data type
4

2 回答 2

2

为什么不这样做(我不确定您是否真的要使用样式 111 = 日本标准 = yy/mm/dd。如果您使用,请考虑一下 style 103 = dd/MM/yyyy)。

select *
from
(
SELECT a, b, c, convert(DateTime, DateField, 103) as mydate FROM whatever  
UNION  
SELECT a, b, c, convert(DateTime, DateField, 103) as mydate FROM whatever  
UNION  
SELECT a, b, c, convert(DateTime, DateField, 103) as mydate FROM whatever  
)
Order By mydate
于 2012-06-01T08:11:42.280 回答
2
SELECT a, b, c, DateField FROM 
(SELECT a, b, c, DateField
FROM whatever

UNION

SELECT a, b, c, DateField
FROM whatever

UNION

SELECT a, b, c, DateField
FROM whatever) x
Order By DateField
于 2012-06-01T08:12:28.980 回答