Avatar of Fred
Fred
Flag for United States of America asked on

Return the answer of Query and Put the results in to a Table variable

I am trying to create a table variable that will store  the output of one query, using the 4 tables

            SELECT COUNT(*)
            FROM      [dbo].[ADF_Path]
            WHERE PathActive = 'y'
            UNION
            SELECT COUNT(*)
            FROM  [dbo].[ADF_Course]
            WHERE CourseActive = 'y'
            UNION
            SELECT COUNT(*)
            FROM      [dbo].[ADF_Section]
            WHERE SectionActive = 'y'
            UNION

DECLARE @ACtiveGroup TABLE
                        
                  (
                        SELECT COUNT(*) FROM      [dbo].[ADF_Path]
                        WHERE PathActive = 'y'
                        UNION
                        SELECT COUNT(*)   FROM  [dbo].[ADF_Course]
                        WHERE CourseActive = 'y'
                        UNION
                        SELECT COUNT(*)  FROM      [dbo].[ADF_Section]
                        WHERE SectionActive = 'y'
                        UNION
                        SELECT COUNT (*) FROM      [dbo].[ADF_Event]
                        WHERE EventActive = 'y'
            )
            
            SELECT FROM  @ACtiveGroup

ADF_Path had 1 record ,Course has 7, Section has 110 and Event has 636 when I run the the query using the where clause. I
SQL

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61