status
列と列を持つテーブルをクエリしようとしていDateSent
ます。私のクエリでは、これらの 2 つの列を 1 つの列に結合しsent
て、ステータスがc
(closed/sent) の場合はDateSent
- を表示し、そうでない場合は適切なステータスを表示するようにします。
でない行はすべてNULLsent
になります。DateSent
以下の望ましい出力:
ID Sent
-----------------
1 Queued
2 Failed
3 2013-02-28
4 Queued
現在の SQL Server CE クエリ:
select
ID, DateAdded,
case when DateSent is null then
(case when Status='W' then 'Waiting' else
case when Status='O' then 'Uploaded' else
case when Status='F' then 'Failed' else
case when Status='E' then 'Expired' else
'Unknown' end end end end) else DateSent
end as Sent
from table
しかし、else DateSent
7 行目の部分でエラーが発生しています。
日付形式に構文エラーがありました。[0, 0, 0,式: 失敗しました,,]
誰かがこの問題を回避する方法を教えてもらえますか?
編集:問題の読みやすいスニペットは次のとおりです。
select case when DateSent is null
then 'null' else DateSent --<---- problem is here
end as Sent from table