I have the following example code:
create table Details(
name varchar(20),
age int,
weight int,
recordDate Datetime)
--insert data
..query:
SELECT a.name,
a.age,
a.recordDate,
a.weight - (SELECT b.weight
FROM Details
WHERE b.recordDate = dateadd(dd, -1, a.recordDate) as subtable)
FROM Details a
GROUP BY WITH ROLLUP (a.recordDate, a.name, a.age)
I want to see the weight difference between RecordDates for each person and then record total weight different for that person and also for the age group and then grand weight gain/loss. This is not my actual table but just an example.
Problem: It was complaining about subquery - then I had to use it as table variable: subtable.
Now it is complaining:
Msg 156, Level 15, State 1, Line 14
Incorrect syntax near the keyword 'as'.
Msg 319, Level 15, State 1, Line 18
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
What am I missing?