【发布时间】:2021-05-15 18:01:30
【问题描述】:
我有这个case语句,我的目标是根据变量“equipo”执行不同的查询
declare @equipo nvarchar(30)
set @equipo='CA10'
SELECT CASE
when @equipo in ('CA10','CA11') then
(select top 100 ReadTime, EquipmentName, ParameterName, ParameterFloatValue
from table
where Equipment=@equipo AND readtime between GETDATE()-15 AND GETDATE())
when @equipo='CA62' then
(select top 100 a.ReadTime, a.EquipmentName, ParameterName, ParameterFloatValue
from table
where Equipment=@equipo AND readtime between GETDATE()-15 AND GETDATE())
else 'nothing'
end
我的问题是:这个查询有什么问题?它不断向我抛出错误:
当不使用 EXISTS 引入子查询时,选择列表中只能指定一个表达式。
【问题讨论】:
-
看起来你想要的是一个
IF声明; SQL Server 不支持Case(Switch) 语句。
标签: sql sql-server tsql case