I am trying to alternate names by querying to view in sql server. The query is as follows,
select
CalendarDate, year, month, day, date, hour,
AVG_VAL, Sum_Val, DVCPORTmc1_Port_No, DVCm_Location,
case
when DVCPORTmc1_SENSOR_Program_name = 'mesh-Cu_1'
then 'Current A/C 1'
else case
when DVCPORTmc1_SENSOR_Program_name = 'mesh-Cu_2'
then 'Current A/C 2'
else case
when DVCPORTmc1_SENSOR_Program_name = 'mesh-Water'
then 'Water'
end
end
as DVCPORTmc1_SENSOR_Program_name
from
[REPORT_Device_Dt_Calendar_YEAR_MONTH_DAY_HOUR]
where
DVCPORTmc1_SENSOR_Program_name like 'mesh-Cu_%' or
where DVCPORTmc1_SENSOR_Program_name like 'mesh-Water'
order by
[year], [month] desc, convert(int, [day]) asc
Which gives the error,
Incorrect syntax near the keyword 'as'.
What is wrong in query?
ends beforeas DVCPORTmc1_SENSOR_Program_nameare redundant