I have a MSSQL statement called from VFP that is Kicking my rear to find the problem. Any help would be welcomed. I'm not a MSSQL fan.
The Resulting table is suppose to return all the other inmates in a Jail facility that had potential contact with other inmates.
This does not involve a prisons that have community rooms like exercise yards, mess halls, ETC.
The query runs, but it returns every person in the database tables in the facility.
Anyone see anything obvious I'm missing.
Any field ending in "ID" is an INTEGER.
Field ADDTIME is Datetime()
the function sqlconv() changes the VFP DateTime to a MSSQL/ORACLE backend statement.
All other fields are CHAR.
I modified the code so it would align and look nice for this forum, there may be a comma out of place in the example because of it
David W. Grewe Dave
The Resulting table is suppose to return all the other inmates in a Jail facility that had potential contact with other inmates.
This does not involve a prisons that have community rooms like exercise yards, mess halls, ETC.
The query runs, but it returns every person in the database tables in the facility.
Anyone see anything obvious I'm missing.
Any field ending in "ID" is an INTEGER.
Field ADDTIME is Datetime()
the function sqlconv() changes the VFP DateTime to a MSSQL/ORACLE backend statement.
All other fields are CHAR.
I modified the code so it would align and look nice for this forum, there may be a comma out of place in the example because of it
Code:
lcBookid = ALLTRIM(STR(lnBookID))
lcSelect = "cellhistid, book_id, newcellid, addtime"
lcWhere = ;
"BOOK_ID = " + lcBookID + ;
" AND addtime <= " + SQLConv(m.vdate2,2) + ;
" AND NEWCELLID IN " + ;
" (SELECT jfaciltyid FROM jfacilty WHERE unit IN " + ;
" (SELECT DISTINCT(unit) FROM jfacilty WHERE jfaciltyid IN " + ;
" (SELECT DISTINCT(newcellid) FROM jcellhist WHERE newcellid > 0 " + ;
" AND book_id = " + lcBookID + ")) " + ;
" AND jsection IN "+;
" (SELECT DISTINCT(jsection) FROM jfacilty WHERE jfaciltyid IN " + ;
" (SELECT DISTINCT(newcellid) FROM jcellhist WHERE newcellid > 0 " + ;
" AND book_id = " + lcBookID + ")) " + ;
" AND facility IN "+;
" (SELECT DISTINCT(facility) FROM jfacilty WHERE jfaciltyid IN " + ;
" (SELECT DISTINCT(newcellid) FROM jcellhist WHERE newcellid > 0 " + ;
" AND book_id = " + lcBookID + ")) )"
SQLProc("SELECT " + lcSelect, ;
"FROM JCELLHIST",;
"WHERE " + lcWhere, ;
"ORDER BY addtime, book_id",;
"INTO TABLE cellhist")
David W. Grewe Dave