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 に答える