SQL Server 2012 query won't save as view
-
11-12-2019 - |
Question
I've got the following fully-working query in SQL Server 2012:
SELECT
iif(((DATEPART(dw, MeasurementTime) + @@DATEFIRST) % 7) < 2,'Weekend','Weekday') AS PartOfWeek,
Seasons.Label AS Season,
CONVERT(TIME,MeasurementTime) AS TimeOfDay,
FeederLoads.FeederNo AS FeederNo,
Avg(FeederLoads.kVA) AS Mean,
StDev(FeederLoads.kVA) AS StdDev
FROM
FeederLoads INNER JOIN
Seasons
ON Month(FeederLoads.MeasurementTime) = Seasons.Month1 OR
Month(FeederLoads.MeasurementTime) = Seasons.Month2 OR
Month(FeederLoads.MeasurementTime) = Seasons.Month3
GROUP BY
((DATEPART(dw, MeasurementTime) + @@DATEFIRST) % 7),
Seasons.Label,
CONVERT(TIME,MeasurementTime),
FeederLoads.FeederNo;
When I copy and paste the query into the SQL pane of the view definition window, however, the view fails to save.
The error message I get is:
Error in list of function arguments: '<' not recognized. Unable to parse query text.
Any ideas why?
Solution
You seem to be running that code in a query designer. Unfortunately, not all designers are created equal - so just take the code and run it in a SQL Server Management Studio query window.
http://sqlfiddle.com/#!6/59d86/1/0
This is no different from some very complex MS Access queries that has to be created in SQL View.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow