【发布时间】:2015-07-30 14:09:55
【问题描述】:
我正在尝试将数据从 SQL Server Management Studio 加载到 Stata。如何让 Stata 运行 .sql 文件?我使用了另一篇文章中的 -ado- 过程,但它不起作用,因为我的数据库有用户名和密码。
原始-ado-代码:
program define loadsql
*! Load the output of an SQL file into Stata, version 1.2 (dvmaster@gmail.com)
version 12.1
syntax using/, DSN(string) [CLEAR NOQuote LOWercase SQLshow ALLSTRing DATESTRing]
#delimit;
tempname mysqlfile exec line;
file open `mysqlfile' using `"`using'"', read text;
file read `mysqlfile' `line';
while r(eof)==0 {;
local `exec' `"``exec'' ``line''"';
file read `mysqlfile' `line';
};
file close `mysqlfile';
odbc load, exec(`"``exec''"') dsn(`"`dsn'"') `clear' `noquote' `lowercase' `sqlshow' `allstring' `datestring';
end;
【问题讨论】:
-
您可以将密码存储为该 DSN 的 ODBC 设置的一部分。
-
感谢您的原始发帖!不幸的是,Stata 要求我重新输入用户名和密码,即使我已将其存储在该 DSN 的 ODBC 设置中,
-
这有点奇怪。无论如何,我编辑了原始代码给你这个选项。