Hey Kids.
I am having a problem with a dynamically generated SQL statement. I have narrowed the problem down to the second 'if' statement not being run. Or at least not having an impct on the SQL.
Here is the SQL
'This part I think is Fine
strSQLQuery = "SELECT tableProducts.UID AS PUID, tableProducts.DEALERUID AS DUID, tableProducts.TANKUID AS TKUID, tableProducts.TRUCKUID AS TRUID, tableProducts.QUANTITY, tableProducts.AVAILABLE, tableProducts.WEBPAGEURL AS PRODURL, tableDealers.NAME AS DEALERNAME, tableDealers.ADDRESS AS DEALERADDR, tableDealers.CITY AS DEALERCITY, tableDealers.PROVINCE AS DEALERPROV, tableDealers.WEBSITEURL AS DEALERURL, tableTanks.ALTERNATE_URL AS ALTURL, tableTanks.NAME AS TANKNAME, tableTrucks.NAME AS TRUCKNAME, tableTrucks.LOGOIMG AS TRUCKLOGO FROM tableTrucks INNER JOIN (tableTanks INNER JOIN (tableDealers INNER JOIN tableProducts ON tableDealers.UID = tableProducts.DEALERUID) ON tableTanks.UID = tableProducts.TANKUID) ON tableTrucks.UID = tableProducts.TRUCKUID"
' Begin the mess
strSQLWhere = ""
if (dbTruckID > 0) then strSQLWhere = strSQLWhere & " tableProducts.TRUCKUID = " & dbTruckID & " AND"
if (dbTankID > 0) then strSQLWhere = strSQLWhere & " tableProducts.TANKUID = " & dbTankID & "AND"
'The above if statemnt is the statement not being run. A valid value is -1071034568. The number is screwy because it is set to random. (not my choice and the table has dependent tables and is replicated)
if not strSQLWhere = "" then strSQLQuery = strSQLQuery & " WHERE" & left(strSQLWhere, Len(strSQLWhere) - 4)
strSQLQuery = strSQLQuery & " ORDER BY "
select case request("sortby"
case "1": strSQLQuery = strSQLQuery & "tableTrucks.NAME"
case "2": strSQLQuery = strSQLQuery & "tableDealers.NAME"
case "3": strSQLQuery = strSQLQuery & "tableProducts.QUANTITY DESC"
case else: strSQLQuery = strSQLQuery & "tableProducts.UID"
end select ************
Caution, dates on calendar are closer then they appear.
I am having a problem with a dynamically generated SQL statement. I have narrowed the problem down to the second 'if' statement not being run. Or at least not having an impct on the SQL.
Here is the SQL
'This part I think is Fine
strSQLQuery = "SELECT tableProducts.UID AS PUID, tableProducts.DEALERUID AS DUID, tableProducts.TANKUID AS TKUID, tableProducts.TRUCKUID AS TRUID, tableProducts.QUANTITY, tableProducts.AVAILABLE, tableProducts.WEBPAGEURL AS PRODURL, tableDealers.NAME AS DEALERNAME, tableDealers.ADDRESS AS DEALERADDR, tableDealers.CITY AS DEALERCITY, tableDealers.PROVINCE AS DEALERPROV, tableDealers.WEBSITEURL AS DEALERURL, tableTanks.ALTERNATE_URL AS ALTURL, tableTanks.NAME AS TANKNAME, tableTrucks.NAME AS TRUCKNAME, tableTrucks.LOGOIMG AS TRUCKLOGO FROM tableTrucks INNER JOIN (tableTanks INNER JOIN (tableDealers INNER JOIN tableProducts ON tableDealers.UID = tableProducts.DEALERUID) ON tableTanks.UID = tableProducts.TANKUID) ON tableTrucks.UID = tableProducts.TRUCKUID"
' Begin the mess
strSQLWhere = ""
if (dbTruckID > 0) then strSQLWhere = strSQLWhere & " tableProducts.TRUCKUID = " & dbTruckID & " AND"
if (dbTankID > 0) then strSQLWhere = strSQLWhere & " tableProducts.TANKUID = " & dbTankID & "AND"
'The above if statemnt is the statement not being run. A valid value is -1071034568. The number is screwy because it is set to random. (not my choice and the table has dependent tables and is replicated)
if not strSQLWhere = "" then strSQLQuery = strSQLQuery & " WHERE" & left(strSQLWhere, Len(strSQLWhere) - 4)
strSQLQuery = strSQLQuery & " ORDER BY "
select case request("sortby"
case "1": strSQLQuery = strSQLQuery & "tableTrucks.NAME"
case "2": strSQLQuery = strSQLQuery & "tableDealers.NAME"
case "3": strSQLQuery = strSQLQuery & "tableProducts.QUANTITY DESC"
case else: strSQLQuery = strSQLQuery & "tableProducts.UID"
end select ************
Caution, dates on calendar are closer then they appear.