SQL error

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

SQL error

Postby Morley » Mon Dec 20, 2004 6:21 pm

In the example below I want SQL to present me with all records where the accountmanager column equals "maarten". Instead I'm being given an error that SQL can't find a column called "maarten".

Note I'm deliberately setting up to search by the contents of a variable derived from an array. I've broken a larger problem so I can debug in parts. A number of contributors to this forum have indicated the way to query sql for instances of a column matching the contents of a variable is the following. Hard coding for '"maarten" also yields the same error.

Test solution called "sqlissue1', using crm server and companies table (form also called companies)
Code: Select all
var a1 = new Array(3);
a1[0] = 'maarten';
a1[1] = 't.banks';
a1[2] = 's.james';
var a1target = a1[0];
var maxReturedRows = 10;
var query = 'select companiesid from companies where accountmanager = ' + a1target;
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
controller.loadRecords(dataset);

Error message is:
dataset com.sybase.jdbc2.jdbc.SybSQLException: ASA Error -143: Column 'maarten' not found ASA Error -143: Column 'maarten' not found


Servoy Developer
Version R2 2.1.2-build 315
Java version 1.4.2_05-b04 (Windows XP)

What am I missing?
Last edited by Morley on Mon Dec 20, 2004 6:35 pm, edited 1 time in total.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Try this way pls

Postby rkrservoy » Mon Dec 20, 2004 6:35 pm

var SQLquery = "SELECT companiesid FROM companies WHERE accountmanager = ' " + a1target + "' " ;

The quotes are important
rkrservoy
 
Posts: 5
Joined: Wed Dec 08, 2004 6:09 pm

Postby Morley » Mon Dec 20, 2004 6:40 pm

Thanks, that worked! That's a lot of quotation marks, obviously necessary.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby Riccardino » Mon Dec 20, 2004 9:11 pm

Morley wrote:Thanks, that worked! That's a lot of quotation marks, obviously necessary.


A little tip: never test your SQL in the method editor.
Use a tool like Interactive SQL or similar: if your code works there and you're getting errors in Servoy, you can be pretty sure is something related to quotes or typos.
ciao, ric
User avatar
Riccardino
 
Posts: 911
Joined: Thu Apr 24, 2003 11:42 am
Location: Ferrara, Italy


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 2 guests