0

I'm supposed to have it present me an address of a property which had people move in within a month after it was listed.

SELECT rp.rp_street, rp.rp_city, rp.rp_state, rp.rp_zipcode
FROM dbo.rentproperty rp
INNER JOIN dbo.rental r
ON (rp.rp_propertyno = r.ren_rp_propertyno)
WHERE r.ren_moveindate BETWEEN rp.rp_datelisted AND rp.rp_datelisted + 30;

I keep getting

Msg 206, Level 16, State 2, Line 1
Operand type clash: date is incompatible with int
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • My bad. Post Edited – Itay Gurvich Feb 10 '17 at 17:51
  • Use `DATEADD`. https://msdn.microsoft.com/en-CA/library/ms186819.aspx. In your case, `DATEADD(DAY, 30, rp.rp_datelisted)`. – Eric Feb 10 '17 at 17:53
  • http://stackoverflow.com/a/923322/2654498 – Nick Feb 10 '17 at 17:58
  • 1
    Please don't edit your question to put things like _solved_ in the title. Instead accept the answer that helped you solve the problem, or - if none of the current answer do that - post your own answer with the solution and - after the timeout - accept that answer. – Mark Rotteveel Feb 10 '17 at 18:02

1 Answers1

3

You can use dateadd(day,n,col) to add days to date:

select rp.rp_street, rp.rp_city, rp.rp_state, rp.rp_zipcode
from dbo.rentproperty rp
inner join dbo.rental r on (rp.rp_propertyno = r.ren_rp_propertyno)
where r.ren_moveindate between rp.rp_datelisted
        and dateadd(day, 30, rp.rp_datelisted);
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76