Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL statement

Status
Not open for further replies.

peekay

Programmer
Oct 11, 1999
324
ZA
I have a problem writing the correct syntax for SQL queries. The present problem is that I wish to select all the records in the Items table in which the field called Catname has the value in the combo box named cboCat(1)which presently have the text value of &quot;None selected&quot;.<br>I use the statement : &quot;select * from Items where catname= &quot; & cboCat(1).text and get the error : Syntax error (missing operator) in query expression 'Catname=none selected'<br>If I use the syntax &quot;select * from Items where catname=cboCat(1).text&quot; it says it does not allow .! or ().<br>Can somebody please help. <p>PK Odendaal<br><a href=mailto: pko@mweb.co.za> pko@mweb.co.za</a><br><a href= > </a><br>
 
One of the problems that i can tell already is that when you specify the field in the database you also have to tell the query what table it is coming from (tablename.fieldname = cbocat(1).text)
 
You need to surround your value with quotes like this:<br><br>&quot;select * from Items where catname = '&quot; & cboCat(1).text & &quot;'&quot;<br><br>It's not necessary to specify the table name unless you have a join with multiple tables that have the same column name.
 
Another problem that will come back and bite you very severly one day is the practice of <br>&quot;Select * from table_name.....&quot;.&nbsp;&nbsp;This extremely poor coding and may cause you problems in Oracle 8 and subsequent versions.&nbsp;&nbsp;You must designate which columns you want even if you want all of the columns of the table.<br><br>If someone adds a column to the table or reforms the table, what will your query do with the extra column or out of order columns.&nbsp;&nbsp;Don't say that will never happen.&nbsp;&nbsp;<br><br>I also know that in RDO and possibly in ADO, you cannot conduct operations on the query result set using Select *.&nbsp;&nbsp;This has something to do with teh query not returning the column names correctly.&nbsp;&nbsp;I know this type of query worked in Oracle 7.34 but not with Oracle 8 and Oracle 8 drivers because I have seen code changed to fix this poor practice.&nbsp;&nbsp;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top