/*************************************** **************************************** *****************
Turtle code
**************************************** **************************************** *****************/
/******* Export to excel */
Exec master.. xp_mongoshell 'bcp settledb. DBO. shanghu out C:/temp1.xls-C-Q-s "gnetdata/gnetdata"-U "sa"-P ""'
/*********** Import Excel */
Select *
From OpenDataSource ('Microsoft. Jet. oledb.4.0 ',
'Data source = "C:/test.xls"; user id = admin; Password =; extended properties = Excel 5.0 ')... xactions
/* Dynamic file name
Declare @ FN varchar (20), @ s varchar (1000)
Set @ fn = 'C:/test.xls'
Set @ s = '''microsoft. Jet. oledb.4.0 '',
''Data Source = "'+ @ fn +'"; User ID = Admin; Password =; Extended properties = Excel 5.0 '''
Set @ s = 'select * FROM OpenDataSource ('+ @ s +')... sheet1 $'
Exec (@ s)
*/
SELECT cast (subject number as numeric (255) as nvarchar () + ''converted alias
FROM OpenDataSource ('Microsoft. Jet. OLEDB.4.0 ',
'Data Source = "c:/test.xls"; User ID = Admin; Password =; Extended properties = Excel 5.0 ')... xactions
/********************** Export to remote SQL in EXCEL */
Insert OPENDATASOURCE (
'Sqlodb ',
'Data Source = remote ip address; User ID = sa; Password = password'
). Database Name. dbo. Table Name (column name 1, column name 2)
SELECT column name 1, column name 2
FROM OpenDataSource ('Microsoft. Jet. OLEDB.4.0 ',
'Data Source = "c:/test.xls"; User ID = Admin; Password =; Extended properties = Excel 5.0 ')... xactions
/** Import a text file */
Exec master .. xp_mongoshell 'bcp dbname .. tablename in C:/dt.txt-C-sservername-USA-ppassword'
/** Export a text file */
Exec master .. xp_mongoshell 'bcp dbname .. tablename out C:/dt.txt-C-sservername-USA-ppassword'
Or
Exec master .. xp_mongoshell 'bcp "select * From dbname .. tablename" queryout C:/dt.txt-C-sservername-USA-ppassword'
/** Export to TXT text, separated by commas */
Exec master.. xp_mongoshell 'bcp "database name... table name" out "D:/tt.txt"-c-t,-U sa-P password'
Bulk insert database name... table name
From 'C:/test.txt'
With (
Fieldterminator = ';',
Rowterminator = '/N'
)
--/* Dbase iv File
Select * from
OpenRowSet ('Microsoft. Jet. oledb.4.0'
, 'Dbase IV; HDR = no; IMEX = 2; database = C:/', 'select * from [customer profile 4.dbf]')
--*/
--/* Dbase iii File
Select * from
OpenRowSet ('Microsoft. Jet. oledb.4.0'
, 'Dbase III; HDR = no; IMEX = 2; database = C:/', 'select * from [customer profile 3.dbf]')
--*/
--/* FoxPro Database
Select * From OpenRowSet ('msdasql ',
'Driver = Microsoft Visual FoxPro driver; sourcetype = DBF; sourcedb = C :/',
'Select * from [AA. DBF] ')
--*/
/************** Import the DBF File ****************/
Select * From OpenRowSet ('msdasql ',
'Driver = Microsoft Visual FoxPro driver;
Sourcedb = E:/vfp98/data;
Sourcetype = DBF ',
'Select * from customer where country! = "USA" order by country ')
Go
/**************** Export to DBF **************
If you want to export data to an existing FoxPro table, you can directly use the following SQL statement */
Insert into OpenRowSet ('msdasql ',
'Driver = Microsoft Visual FoxPro Driver; SourceType = DBF; SourceDB = c :/',
'Select * from [aa. DBF] ')
Select * from table
/* Description:
SourceDB = c:/Specify the folder where the foxpro table is located
Aa. DBF specifies the name of The foxpro table .*/
********************/
Insert into openrowset ('Microsoft. Jet. OLEDB.4.0 ',
'X:/A. mdb '; 'admin'; '', table A) select * from database name... Table B
/************* Import Access ********************/
Insert into B Table selet * from openrowset ('Microsoft. Jet. OLEDB.4.0 ',
'X:/A. mdb '; 'admin'; '', Table)
/* The file name is a parameter */
Declare @ fname varchar (20)
Set @ fname = 'd:/test. mdb'
Exec ('select a. * FROM opendatasource (''microsoft. Jet. OLEDB.4.0 '',
''' + @ Fname + '''; ''admin''; ''', topics) as ')
SELECT *
FROM OpenDataSource ('Microsoft. Jet. OLEDB.4.0 ',
'Data Source = "f:/northwind. mdb"; Jet OLEDB: Database Password = 123; User ID = Admin; Password =; ')... product