Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: How to cite a macro in ODBC's SQL select statement

From   Nick Cox <>
To   "''" <>
Subject   st: RE: How to cite a macro in ODBC's SQL select statement
Date   Fri, 18 Nov 2011 17:01:14 +0000

-odbc- is in the first instance here a Stata command. The key point therefore is that local (and global) macro references are interpreted by Stata before -odbc- gets to work and long before any SQL stuff. So, I think Stata technical support would need to see evidence for your claim. It's likely to be something mundane, such as your defining the locals somewhere where your -odbc- statement cannot see them. 


G. Dai

I have one problem about how to cite macro in ODBC.
For example, I try to read some variables yesterday's value into the
memory of Stata, what I did is

local todate=date(c(current_date),"DMY")
local ydate=`todate'-1
local yyear=year(`ydate')
local ymonth=month(`ydate')
local yday=day(`ydate')

BEGIN_DATE BETWEEN TO_DATE ('`ymonth'/`yday'/`yyear' 00', 'MM/DD/YYYY
HH24') AND TO_DATE  ('`ymonth'/`yday'/`yyear' 00', 'MM/DD/YYYY
HH24')")  dsn("SQL Database1")

However, this doesn't work since the SQL select statement ignors the
Stata macro.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index