我知道以下是合法的SQL查询,但为什么这不能在SQL Server Compact中解释? (我正在使用SQL Server Compact视图)
Select
Case AStatus
When 1 then 'Success', 'AStatus', 'Expected:1'
When 0 then 'Faliure', 'AStatus', 'Recived: 0'
end
From Statuses
Where LocalPath= 'c:\Status
我得到类似的东西:
查询1:解析查询时出错[令牌行号= 3,令牌行偏移= 22,错误令牌=,]
当写下类似的内容时,它会起作用:
Select
Case AStatus
When 1 then 'Success'
When 0 then 'Faliure'
end
From Statuses
Where LocalPath= 'c:\Status
答案 0 :(得分:2)
我认为这是从案例中获取三列的唯一有效方法:
Select
Case AStatus
When 1 then 'Success'
When 0 then 'Faliure'
END,
Case AStatus
When 1 then 'AStatus'
When 0 then 'AStatus'
END,
Case AStatus
When 1 then 'Expected:1'
When 0 then 'Recived: 0'
END
From Statuses
Where LocalPath= 'c:\Status'
编辑: 其他方式。不短,但似乎更灵活:
Select
Astatus,
x.*
From Statuses s
CROSS APPLY (
select 'Success' as c1,'AStatus' as c2,'Expected:1' as c3 where AStatus=1 union all
select 'Failure' ,'AStatus','Recived:0' where AStatus=0
) x
Where LocalPath= 'c:\Status'
你让我得到+1,我已经知道我会在哪里使用它:)。
答案 1 :(得分:1)
您的陈述缺少END
语句中的CASE
条款我不知道这是否是唯一的错误尝试第1次
Select
Case AStatus
When 1 then 'Success', 'AStatus', 'Expected:1'
When 0 then 'Faliure', 'AStatus', 'Recived: 0'
END
From Statuses
Where LocalPath= 'c:\Status