Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 



Are there any examples of heterogeneous data queries from SQL 7 to other sources?

RSS
Subscribe to Windows IT Pro | See More SQL Server 7.0 Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

A. Here are a variety of examples for several different datasources. Note that you will have to change filenames, drives, regions etc. as necessary for your environment :-

1. Selecting from an Excel spreadsheet using OpenRowSet. Here, c:\ramsql7.xls is a spreadsheet (note we haven't specified the extension). sheet1 is a sheet within the spreadsheet - note the trailing $.

SELECT * FROM OpenRowSet 
('MSDASQL', 'Driver=Microsoft Excel Driver (*.xls);DBQ=c:\ramsql7', 'SELECT * FROM [sheet1$]') 
as a

2. Selecting from an Access linked server database via Jet. The Access database is at c:\msd\invent97.mdb

print 'add Jet 4.0 Invent'
-- Clear up old entry
if exists(select * from sysservers where srvname = N'INV')
exec sp_dropserver N'INV', N'droplogins'
go
-- create linked server
exec sp_addlinkedserver @server = N'INV', @srvproduct = '', @provider =
N'Microsoft.Jet.OLEDB.4.0', @datasrc = N'c:\msd\invent97.mdb'
go
-- setup default admin login for Access
exec sp_addlinkedsrvlogin @rmtsrvname = N'INV', @useself = N'FALSE',
@locallogin = NULL, @rmtuser = N'admin', @rmtpassword = N''
go
-- Lists all tables in the linked server
exec sp_tables_ex N'INV'
go
-- Now select from a table in the Access db called INVENT 
select * from INV...INVENT
go

3. DB/2 accessed via Star SQL Driver with SNA 4.0.

print 'add DB2 LinkedServer'
if exists(select * from sysservers where srvname = N'DB2')
exec sp_dropserver N'DB2', N'droplogins'

exec sp_addlinkedserver @server = 'DB2', @provider = 'MSDASQL', @srvproduct
= 'StarSQL 32',
@location = 'DBT1', @datasrc = 'DB2IBM'
exec sp_addlinkedsrvlogin @rmtsrvname = 'DB2', @locallogin = 'sa', @useself
= 'false',
@rmtuser = 'HDRUSER' ,@rmtpassword = 'SQL7'
go

-- test to see is catalog is accesible
sp_tables_ex N'DB2'

-- create view to see if select works
create view V007MUNI as select * from DB2..T1ADM007.V007MUNI
go
select * from V007MUNI
go

4. DBASE IV

print 'add DBase IV LinkedServer'
if exists(select * from sysservers where srvname = N'DBFs')
exec sp_dropserver N'DBFs', N'droplogins'

EXEC sp_addlinkedserver
'DBFs',
'Jet 4.0',
'Microsoft.Jet.OLEDB.4.0',
'F:\DBFs',
NULL,
'dBase IV'
GO

exec sp_addlinkedsrvlogin
@rmtsrvname = 'DBFs',
@useself = false,
@locallogin = NULL,
@rmtuser = NULL,
@rmtpassword = NULL
go

SELECT * FROM DBFs...test
go

5. Visual FoxPro. Using a FoxPro DBC file to group the DBF files. ODBC DSN pre-defined called FOX using the Microsoft Visual FoxPro Driver 6.01.8440.01

-- FOX using Visual FoxPro Database file .DBC
print 'add FOXSERVER'
if exists(select * from sysservers where srvname = N'FOXSERVER')
exec sp_dropserver N'FOXSERVER', N'droplogins'

exec sp_addlinkedserver @server=N'FOXSERVER',
@srvproduct ='',
@provider = N'MSDASQL',
@datasrc=N'FOX'

exec sp_addlinkedsrvlogin @rmtsrvname=N'FOXSERVER',
@useself = N'FALSE',
@locallogin = NULL,
@rmtuser = N'',
@rmtpassword =N''


exec sp_tables_ex N'FOXSERVER'

select * from [FOXSERVER].[D:\SQL\FOX\TESTDATA.DBC]..[customer]

6. FoxPro using plain DBF files in a directory. Using an ODBC system DSN (Called DBF) using the Microsoft Visual FoxPro Driver 6.01.8440.01

-- DBF using plain .DBF files
print 'add DBFSERVER'
if exists(select * from sysservers where srvname = N'DBFSERVER')
exec sp_dropserver N'DBFSERVER', N'droplogins'

exec sp_addlinkedserver @server=N'DBFSERVER',
@srvproduct ='',
@provider = N'MSDASQL',
@datasrc=N'DBF'

exec sp_addlinkedsrvlogin @rmtsrvname=N'DBFSERVER',
@useself = N'FALSE',
@locallogin = NULL,
@rmtuser = N'',
@rmtpassword =N''

exec sp_tables_ex N'DBFSERVER'

select * from [DBFSERVER].[D:\SQL\DBF]..[country]

7. FoxPro using installable Jet 3.51 ISAM drivers.

print 'add FOXDBC using Jet 3.51'
if exists(select * from sysservers where srvname = N'FOXDBC')
exec sp_dropserver N'FOXDBC', N'droplogins'
exec sp_addlinkedserver 'FOXDBC', 'Jet 3.51', 'Microsoft.Jet.OLEDB.3.51',
'c:\sql\fox', NULL, 'FoxPro 3.0'
exec sp_addlinkedsrvlogin @rmtsrvname = N'FOXDBC', @useself = N'FALSE',
@locallogin = NULL, @rmtuser = NULL, @rmtpassword = NULL
exec sp_helplinkedsrvlogin N'FOXDBC'
exec sp_tables_ex N'FOXDBC'


End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...


Related Events SQL Server Unleashed EMEA

Deep Dive into Windows Server 2008 R2 presented by John Savill

The Easiest Way to Save Time and Money on E-mail and SharePoint Management

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement