I'm getting a syntax error on this query and no one here (including yours truly) can figure out what SQL is REALLY trying to say.
Here's the code:
declare @VarKey int
set @VarKey = 3
UPDATE Schema1.Table
SET Rate = gl.Rate
FROM dbo.RateView gl WHERE gl.RateId = (SELECT RateId FROM Schema2.Table BP INNER JOIN Schema2.Table2 RA ON BP.TableId = RA.TableId
INNER JOIN Schema1.Table VI ON RA.Table2NotId = VI.Table2NotId
WHERE BP.OtherKey = @CompanyId)
GROUP BY gl.Rate
HAVING MIN(DATEDIFF(ss, gl.rateDate, VI.OtherDate)) < 0
And when I test I get this innocuous error:
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'GROUP'.
When I comment out both the GROUP BY and HAVING lines, it is happy. 'Course, then it's useless. What rule am I violating?
Thanks!
"Always code as if the person who ends up maintaining your code will be a violent psychopath who knows where you live." -- Martin Golding
Here's the code:
declare @VarKey int
set @VarKey = 3
UPDATE Schema1.Table
SET Rate = gl.Rate
FROM dbo.RateView gl WHERE gl.RateId = (SELECT RateId FROM Schema2.Table BP INNER JOIN Schema2.Table2 RA ON BP.TableId = RA.TableId
INNER JOIN Schema1.Table VI ON RA.Table2NotId = VI.Table2NotId
WHERE BP.OtherKey = @CompanyId)
GROUP BY gl.Rate
HAVING MIN(DATEDIFF(ss, gl.rateDate, VI.OtherDate)) < 0
And when I test I get this innocuous error:
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'GROUP'.
When I comment out both the GROUP BY and HAVING lines, it is happy. 'Course, then it's useless. What rule am I violating?
Thanks!
"Always code as if the person who ends up maintaining your code will be a violent psychopath who knows where you live." -- Martin Golding