Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Too many decimal places for ODBC - thanks


From   Gawrich Stefan <s.gawrich@hlpug.hessen.de>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Too many decimal places for ODBC - thanks
Date   Thu, 15 May 2008 10:43:24 +0200

Thanks to Joseph Coveney for pointing out the solution and Kit Baum for
writing 'tosql'.
Couldn't be easier :-)
 
For routine use it's nice to have a - database-specific - table creation
script.
Here's mine for firebird:

foreach x of varlist _all {
local vars "`vars' `x'" // Local of vars
local typ : type `x' // Data type of var `x'
**** Database specific: Type conversion
if "`typ'" == "byte" | "`typ'" == "int" | "`typ'" == "long" local typefb =
"INTEGER" // Integer in Firebird
if substr("`typ'",1,3) == "str" local typefb = "CHAR("+
substr("`typ'",4,3)+")" // Char in Firebird (Stata: str123 => CHAR(123))
if "`typ'" == "float" local typefb = "FLOAT" // Float in Firebird
** [...]
local typenfb  "`typenfb'  `typefb'" // Local of Firebird data types for all
vars
}

*** Variable declarations for "Create Table"
local varnum : word count `vars'
forval i = 1/`varnum' {
local a : word `i' of `vars'
local b : word `i' of `typenfb'
if `i' < `varnum' local crea  "`a' `b'," //  a comma after each var
declaration...
if `i' == `varnum' local crea  "`a' `b'" // ...but not after the last var.
local create "`create' `crea'" // all variable declarations together 
}

*** Finally the odbc command
odbc exec("create table tablename (`create')"), dsn(dsnname) // 





Best wishes

Stefan Gawrich
Dillenburg
Germany
*
*   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