Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Report from multiple SQL Databases
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01653049
Message ID:
01653076
Vues:
52
>Hi,
>
>I think that theoretically it is possible to create a report (from VFP or maybe even other tools) that gets/pulls data from various SQL Server databases (even hosted by different SQL Servers).
>But I was wondering, has anybody done it and do you find it practical?
>
>I am "drafting" an approach of creating a report for a corporate that shows how the data is used in misc branches.
>
>TIA

Not long ago I did a query on all databases in one SQL Server instance, and it worked well:
SET NOCOUNT ON;

IF OBJECT_ID (N'tempdb.dbo.#temp') IS NOT NULL
   DROP TABLE #temp

CREATE TABLE #temp
(
       DB VARCHAR(50)
       , emNumber Character(10)
     , emName VARCHAR(50)
     , emFirst VARCHAR(50)
)

DECLARE @TableName NVARCHAR(50) 
SELECT @TableName = '[dbo].[Employees]'

DECLARE @SQL NVARCHAR(MAX)
SELECT @SQL = STUFF((
    SELECT CHAR(13) + 'SELECT ''' + name + ''', emNumber, emName, emFirst '
       + ' FROM [' + name + '].' + @TableName
       + ' WHERE delFlag = 0 AND emArchived = 0 '
    FROM sys.databases 
    WHERE OBJECT_ID(name + '.' + @TableName) IS NOT NULL
    FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')

INSERT INTO #temp (DB, emNumber, emName, emFirst)              
EXEC sys.sp_executesql @SQL

SELECT * 
FROM #temp t
Christian Isberner
Software Consultant
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform