Link to home
Start Free TrialLog in
Avatar of Fred
FredFlag 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
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial