我正在使用该CASE
命令将子字符串查询结果从数字更改为名称。
事情似乎工作正常,但我很难弄清楚为什么结果只显示字符串的第一个值。
Declare @OverrideON INT, @OverrideOFF INT
SET @OverrideON = 1 SET @OverrideOFF = 0
SELECT LonDeviceName,
CASE WHEN SUBSTRING (PointValue,65,1) = @OverrideON THEN 'Fan In Override'
WHEN SUBSTRING (PointValue,67,1) = @OverrideON THEN 'HW In Override'
WHEN SUBSTRING (PointValue,69,1) = @OverrideON THEN 'CHW In Override'
WHEN SUBSTRING (PointValue,71,1) = @OverrideON THEN 'OAD In Override'
WHEN SUBSTRING (PointValue,73,1) = @OverrideON THEN 'VFD In Override'
WHEN SUBSTRING (PointValue,65,1) = @OverrideOFF THEN 'Fan Normal'
WHEN SUBSTRING (PointValue,67,1) = @OverrideOFF THEN 'HW Normal'
WHEN SUBSTRING (PointValue,69,1) = @OverrideOFF THEN 'CHW Normal'
WHEN SUBSTRING (PointValue,71,1) = @OverrideOFF THEN 'OAD Normal'
WHEN SUBSTRING (PointValue,73,1) = @OverrideOFF THEN 'VFD Normal'
ELSE '**StringError**'
END as 'Manual Overrides'
FROM dbo.Points
WHERE LogicName like '%override%'
当代码运行时,它会创建一个标题Manual Overrides
为正确的列,在该列中显示字符串中的第一个值。但是,字符串中其他四个值的结果在哪里。任何帮助或想法将不胜感激。
谢谢。