Q:

Get data from table where date between given date and 1 week back

I have database dbadmin, table - tbl_empreimburse with fields-emp_id,rem_amount,rem_date.
I want to retrieve data which comes from given date to a week back.
I tried this query,
SELECT SUM(rem_amount),DATEADD(dd, -7, "2012-01-10")  
FROM tbl_empreimburse 
GROUP BY emp_id 
HAVING emp_id='5' AND rem_date BETWEEN DATEADD(dd, -7, "2012-01-10") AND "2012-01-10"

It gives me error "FUNCTION dbadmin.DATEADD does not exist". Do I need to convert "2012-01-10"  to date format? Any Help, Please?

A:

Check this *SQLFIDDLE reference out. :)
I am not sure why you are using group by clause here...
Sample date:
ID  AMOUNT  RDATE
1   3400    January, 01 2012 00:00:00+0000
2   5000    January, 10 2012 00:00:00+0000
3   3000    January, 02 2012 00:00:00+0000
5   1000    January, 05 2012 00:00:00+0000
5   2000    January, 04 2012 00:00:00+0000
2   2000    February, 10 2012 00:00:00+0000

Query:
select * from emp
where id = 5;

here is the query to get sum
select id, sum(amount)
from emp
where rdate between '2012-01-10' - interval 7 day
and '2012-01-10'
and id = 5
;

Results:
all records by employee id = 5
ID  AMOUNT  RDATE
5   1000    January, 05 2012 00:00:00+0000
5   2000    January, 04 2012 00:00:00+0000

sum of amount by employee id = 5
ID  SUM(AMOUNT)
5   3000

