0

Please help me, below is my sql query. When I execute it, the result is nothing.

SELECT tblclientinfo.acctnum, 
       tblclientinfo.fname, 
       tblclientinfo.fname, 
       tblreservation.unitnum, 
       tblbillingsched.billnum, 
       tblbillingsched.duedate, 
       tblbillingsched.monthlyamort, 
       tblbillingsched.totalbalance 
FROM   tblclientinfo 
       JOIN tblreservation 
         ON tblclientinfo.acctnum = tblreservation.reservationnum 
       JOIN tblbillingsched 
         ON tblreservation.reservationnum = tblbillingsched.accountnum 
WHERE  tblbillingsched.accountnum = 'C0000000021' 
       AND tblbillingsched.duedate BETWEEN '1/1/2014' AND '1/30/2014'

Here are my tables:

tblClientInfo, pk = acctNum
tblReservation, pk = ReservationNum, fk = accountNum
tblBillingSched, pk = ID,  fk = accountNum
Kermit
  • 33,827
  • 13
  • 85
  • 121
Sishan
  • 79
  • 1
  • 1
  • 11
  • Are you sure you have data that meets those filters? – Shawn Sep 26 '13 at 13:36
  • Thanks guys for your prompt reply but the result is still empty. I double check every table and all of them have data. I think my pk and fk is the problem but I don't know how to fix it. Please see my table relationship picture. [link](http://farm6.staticflickr.com/5520/9950519065_06207ec31e_z.jpg) – Sishan Sep 26 '13 at 14:03

4 Answers4

1

I think you're looking for...

SELECT tblclientinfo.acctnum, 
       tblclientinfo.fname, 
       tblclientinfo.fname, 
       tblreservation.unitnum, 
       tblbillingsched.billnum, 
       tblbillingsched.duedate, 
       tblbillingsched.monthlyamort, 
       tblbillingsched.totalbalance 
FROM   tblclientinfo 
       JOIN tblreservation 
         ON tblclientinfo.acctnum = tblreservation.accountnum 
       JOIN tblbillingsched 
         ON tblclientinfo.acctnum = tblbillingsched.accountnum 
WHERE  tblbillingsched.accountnum = 'C0000000021' 
       AND tblbillingsched.duedate BETWEEN '1/1/2014' AND '1/30/2014'

See a demo

Kermit
  • 33,827
  • 13
  • 85
  • 121
0

Your first join is wrong. In the table tblReservation the foreignkey is accountNum an you make the join with the field reservationnum. The code should be this:

SELECT tblclientinfo.acctnum, 
    `tblclientinfo.fname, 
     tblclientinfo.fname, 
     tblreservation.unitnum, 
     tblbillingsched.billnum, 
     tblbillingsched.duedate, 
     tblbillingsched.monthlyamort, 
     tblbillingsched.totalbalance 
FROM tblclientinfo 
     JOIN tblreservation 
     ON tblclientinfo.acctnum = tblreservation.accountNum 
     JOIN tblbillingsched 
     ON tblreservation.reservationnum = tblbillingsched.accountnum 
WHERE  tblbillingsched.accountnum = 'C0000000021' 
       AND tblbillingsched.duedate BETWEEN '1/1/2014' AND '1/30/2014'
Allan
  • 17,141
  • 4
  • 52
  • 69
OliC
  • 175
  • 6
0

Is DueDate a Date time field Try the following and see if it works:

CAST(tblbillingsched.duedate AS DATE) BETWEEN '1/1/2014' AND '1/30/2014'

Check out this post for a more detailed discussion:

how to query Datetime object by date?

Community
  • 1
  • 1
harifx
  • 60
  • 7
0

(off topic and probably not the answer but I thought worth noting)

The safer form of this:

tblbillingsched.duedate BETWEEN '1/1/2014' AND '1/30/2014'

is this:

tblbillingsched.duedate >= '20140101' AND 
tblbillingsched.duedate <'20140130'

Stating a date like this '20140130' is unmistakable.

whytheq
  • 34,466
  • 65
  • 172
  • 267