Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: WHERE SQL clause


From   kturner@stata.com (Kevin Turner)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: WHERE SQL clause
Date   Mon, 03 Feb 2003 09:24:33 -0600

Alberto Tosetto, M.D. <tosetto@hemato.ven.it> wrote:

>I am having a problem with the odbc command on Stata 8.0. When I use
>the exec("...") option in the odbc load command, everything works fine
>provided that the SQL WHERE statement does not address VARCHAR values.
>For instance, if I try the following SQL statement 
>
>SELECT * FROM MYTABLE, WHERE GENDER="F"
>
>Stata gives me back the following message: table() or exec() is required


The short answer is to use single quotes for any quoted value in your SQL
statement. 

	SELECT * FROM MYTABLE, WHERE GENDER='F'

Most ODBC Drivers, and the SQL servers they connect to, actually prefer single
quotes within SQL commands. All SQL servers we have tested take both single
and double as interchangeable. The Stata command line parser, however, does 
not identify double quotes as valid syntax at this time so you will be required 
to use single quotes. 

In the near future Stata will most likely either 1) support double quotes in
a way that is compatible with all SQL servers, or 2) display a better error 
message if the Stata parser doesn't support double quotes.

--Kevin 
kturner@stata.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index