Excuse my ignorance on this question if it is really simple but its driving me crazy and I have searched (tried and failed) different solutions from this site so here goes…
I am using SQL 2008 and trying to pull results from 12 tables into a single query so I have;
DECLARE @RefID nvarchar(10)
SET @RefID = 'test'
SELECT * From
Table1,
Table2,
Table3,
Table4,
Table5,
Table6,
Table7,
Table8,
Table9,
Table10,
Table11,
Table12
WHERE table1.[RefID] = @RefID
AND Table2.[Ref ID] = @RefID
AND Table3.[Ref ID] = @RefID
AND Table4.[Ref ID] = @RefID
AND Table5.[Ref ID] = @RefID
AND Table6.[Ref ID] = @RefID
AND Table7.[Ref ID] = @RefID
AND Table8.[Ref ID] = @RefID
AND Table9.[Ref ID] = @RefID
AND Table10.[Ref ID] = @RefID
AND Table11.[RefID] = @RefID
AND Table12.[RefID] = @RefID `
Now this works fine, is easy to understand and gives me one row will all the data which is exactly what I was looking for.. except with one issue
If a record does not exist in any of the tables, instead of ignoring it or simply give me blank/null values for that table – the query breaks down and I get no results
I would really appreciate any ideas
TIA
Realised the first two ideas weren’t right:
If you don’t want the extra RefID at the start, then replace
*withTable1.*, Table2.*, ...