SQL Server | Other
Additional SQL Server features and topics not covered by specific categories
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need to union results from two databases using fully qualified objects/views but the query after the union returns zero rows.
Additional SQL Server features and topics not covered by specific categories
I guess then that your tables are empty, or that your WHERE conditions filter out all rows.
Since I don't possess a crystal ball, I can't say more exactly why you don't get any data back, but if you as a start share the query, we might be able to say something more useful.
In the meanwhile, here is an example of a UNION query that does return rows:
CREATE DATABASE DB111
CREATE DATABASE DB222
go
USE DB111
go
CREATE TABLE pannkaka (a int NOT NULL,
b varchar(123) NOT NULL,
CONSTRAINT pk_pannkaka PRIMARY KEY (a)
)
INSERT pannkaka(a, b)
SELECT object_id, name
FROM sys.objects
go
USE DB222
go
CREATE TABLE korvomos (a int NOT NULL,
b varchar(123) NOT NULL,
CONSTRAINT pk_korvomos PRIMARY KEY (a)
)
INSERT korvomos(a, b)
SELECT object_id, name
FROM sys.objects
go
USE tempdb
go
SELECT a, b
FROM DB111.dbo.pannkaka
WHERE b LIKE '%obj%'
UNION ALL
SELECT a, b
FROM DB222.dbo.korvomos
WHERE b LIKE '%hob%'
go
DROP DATABASE DB111, DB222