I've got a sql statement that I'm having a problem with. There's a variable called property that I've created that will have a value of 1, 2 or 3. I know that the variable has a value because before the sql statement I've put an answer statement that tells me what the value of the variable is. The sql statement is:
revDB Error: revdberr, Database Error: no such column: property.
Maybe I'm misinterpreting the error message, but it seems to be looking for a column in one of the tables called property. I'll change the name of the variable in case property is a reserved word.
Peter, a variable enclosed within double quotes is no longer a variable. It's now treated as a literal. You have to close the quoted portion of the argument and append the variable using & or &&, as appropriate. If it's in the middle of such an argument you then continue by appending the rest of the argument with another & or && and the rest, within double quotes of course.
It can be clumsy and confusing and sometimes requires experimentation to get it right when you're just getting started. (Was, and still is, for me, anyway )
select .....
from .....
where (select max(userID) from borrowers), ....
I'm getting a syntax error message near ",". I get a syntax error message if I take the comma out also.
results in a sql query of the sort "select <data> from <table> where 876"
(876 is of course an arbitrary value I made up)
Try "where tablekey = (select max(userID) from borrowers)" perhaps? ie, give the where clause a column to match. Otherwise, please can we see more of the query syntax?
I'll try everyone's suggestions and post the query when I get home tonight.
In the meantime I've gone further in the development of my system and I've come across an issue that I can't solve. I'm using the Case statement in a select statement to do some math. The first part (if the column value = '1') works fine there's just multiplication and division in it. However the math for the second part (if the column value = '2') contains some exponentiation in it. Other forms of SQL seem to be able to handle this, but I can't figure out how to do this in SQLite.
put "Select mortgage_rates.loan_type, CASE mortgage_rates.int_only when '1' then 'No' when '2' then 'Yes' END, mortgage_rates.int_rate, " & \
"CASE mortgage_rates.int_only when '1' then cust_info.loan_amt * ((mortgage_rates.int_rate/1200)/((1-(1-mortgage_rates.int_rate/1200)*-360))) when '2' then (cust_info.loan_amt * mortgage_rates.int_rate/100)/12 END, " & \
"cust_info.bank_name, cust_info.p_price, cust_info.loan_amt, cust_info.ltv, cust_info.min_loan, cust_info.max_loan, " & \
"cust_info.name, cust_info.prop_addr, cust_info.prop_type " & \
"from cust_info, mortgage_rates where cust_info.bank_number = mortgage_rates.bank_number " & \
"and cust_info.loan_amt > mortgage_rates.min_loan " & \
"and cust_info.loan_amt <= mortgage_rates.max_loan and " & prop & " = mortgage_rates.prop_type " & \
"order by mortgage_rates.loan_type" into tSQL
The first case statement is fine, it's the second that's giving me problems. If mortgage_rates.int_only = '1' I have to calculate monthly mortgage payments paying principle and interest. It's called compound interest. the *-360 on the second line should be exponentiation (to the negative 360 power). I can't figure our how to do exponentiation in SQLite.