Amour22015
asked on
SQl Server 2012 r2 - Why temp table shrinks from large query
Hi Experts:
I have this part of a query:
I get 4,830,682 records
yet when I introduce the temp table:
I get 335 records
Why?
I want all the records that come up in the query to go into the Temp Table.
Please help and thanks
I have this part of a query:
-- Adobe Category
-- Adobe Category
SELECT
Scandate
,'Adobe' as Category
,rs.[Plugin]
,rs.IPLong
FROM [FODW_PVT].[Dflt].[Systems] as rs
INNER JOIN Dflt.Vulnerabilities as vn on vn.Plugin = rs.Plugin
INNER JOIN (SELECT distinct Plugin, Category
FROM [FODW_PVT].[Dflt].[CVA_App_Catalog]
Where Category like '%Adobe%'
) as Cat On Cat.Plugin = rs.Plugin
WHERE rs.ScandateID in (Select top (6 ) id from dflt.scandates order by id desc)
and vn.Severity in ('Critical', 'High')
Group By ScanDate, rs.Plugin, rs.IPLong
Order By Scandate desc
-- Adobe Category
-- 6 month
-- without temp table
-- 4,830,682 records
-- 2.24 sec
-- Temp table
-- 335 records
-- 4.02 sec
-- End Adobe Category
I get 4,830,682 records
yet when I introduce the temp table:
-- Adobe Category
IF OBJECT_ID('TempDB..##tmpAdobe') IS NOT NULL
DROP TABLE ##tmpAdobe;
CREATE TABLE ##tmpAdobe(
Scandate Date NULL,
Category [varchar](255) NULL,
Plugin int PRIMARY KEY CLUSTERED WITH (IGNORE_DUP_KEY = ON),
IPLong Bigint NULL,
)
Insert into ##tmpAdobe (Scandate, Category, Plugin, IPLong)
SELECT
Scandate
,'Adobe' as Category
,rs.[Plugin]
,rs.IPLong
FROM [FODW_PVT].[Dflt].[Systems] as rs
INNER JOIN Dflt.Vulnerabilities as vn on vn.Plugin = rs.Plugin
INNER JOIN (SELECT distinct Plugin, Category
FROM [FODW_PVT].[Dflt].[CVA_App_Catalog]
Where Category like '%Adobe%'
) as Cat On Cat.Plugin = rs.Plugin
WHERE rs.ScandateID in (Select top (6 ) id from dflt.scandates order by id desc)
and vn.Severity in ('Critical', 'High')
Group By ScanDate, rs.Plugin, rs.IPLong
Order By Scandate desc
-- Temp Table
Select
AB.Scandate,
AB.Category,
AB.Plugin,
AB.IPLong
From ##tmpAdobe AB -- Adobe Category
-- Adobe Category
-- 6 month
-- without temp table
-- 4,830,682 records
-- 2.24 sec
-- Temp table
-- 335 records
-- 4.02 sec
-- End Adobe Category
I get 335 records
Why?
I want all the records that come up in the query to go into the Temp Table.
Please help and thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER