getDataSetByQuery() question

This is my first attempt at using this function. I’m attempting to find all records which have the current value of the field “catkey”. Therefore I’m first putting the target value into the variable “key”. However I’m getting an error message saying it can’t find the column “key”. Obviously a syntax error, but what?

var key = catkey;
var maxReturedRows = 10;//useful to limit number of rows
var query = 'SELECT catid FROM cat WHERE catkey = key';
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);

You’re statement says:

give me catid from cat where the column catkey equals the column key.

If there is no column key, you get an error. What you want to do is:

var query = 'select catid from cat where catkey = ' + key

This only works if catkey is a number column. If it is string, you need to take care of "…

Much thanks, Patrick.

Morley, why don’t you check out 'www.sqlcourse.com. This will help you with the basics of working with sql statements…

IT2BE:
Morley, why don’t you check out 'www.sqlcourse.com. This will help you with the basics of working with sql statements…

Excellent, exactly what I needed. Thanks.