SQLTeam.com | Weblogs | Forums

Save Query Reults to a new table View

I have the correct output that I need but I need to get these results of this query into a table view or a new table. I cannot figure out how to perform that.

SELECT CARDHOLDERS.LAST_NAME, CARDHOLDERS.FIRST_NAME, LOOPS.LOOP_NAME, ACCESS_GROUPS.NAME, CARDHOLDERS.EMPLOYEE_ID, CARD_LOOP_DETAILS.EMPLOYEE_ID AS Expr1

FROM CARDHOLDERS AS CARDHOLDERS INNER JOIN
CARD_LOOP_DETAILS AS CARD_LOOP_DETAILS ON CARDHOLDERS.EMPLOYEE_ID = CARD_LOOP_DETAILS.EMPLOYEE_ID INNER JOIN
LOOPS AS LOOPS ON CARD_LOOP_DETAILS.LOOP_ID = LOOPS.LOOP_ID LEFT OUTER JOIN
ACCESS_GROUPS AS ACCESS_GROUPS ON CARD_LOOP_DETAILS.ACCESS_GROUP_NUMBER_LOOP_ID = ACCESS_GROUPS.LOOP_ID AND
CARD_LOOP_DETAILS.ACCESS_GROUP_NUMBER = ACCESS_GROUPS.ACCESS_GROUP_NUMBER
ORDER BY CARDHOLDERS.LAST_NAME, CARDHOLDERS.FIRST_NAME, LOOPS.LOOP_NAME

To create a new table of the results, you can use INTO, like so:


SELECT CARDHOLDERS.LAST_NAME, CARDHOLDERS.FIRST_NAME, LOOPS.LOOP_NAME, ACCESS_GROUPS.NAME, CARDHOLDERS.EMPLOYEE_ID, CARD_LOOP_DETAILS.EMPLOYEE_ID AS Expr1

INTO dbo.query_results

FROM CARDHOLDERS AS CARDHOLDERS INNER JOIN
CARD_LOOP_DETAILS AS CARD_LOOP_DETAILS ON CARDHOLDERS.EMPLOYEE_ID = CARD_LOOP_DETAILS.EMPLOYEE_ID INNER JOIN
LOOPS AS LOOPS ON CARD_LOOP_DETAILS.LOOP_ID = LOOPS.LOOP_ID LEFT OUTER JOIN
ACCESS_GROUPS AS ACCESS_GROUPS ON CARD_LOOP_DETAILS.ACCESS_GROUP_NUMBER_LOOP_ID = ACCESS_GROUPS.LOOP_ID AND
CARD_LOOP_DETAILS.ACCESS_GROUP_NUMBER = ACCESS_GROUPS.ACCESS_GROUP_NUMBER
ORDER BY CARDHOLDERS.LAST_NAME, CARDHOLDERS.FIRST_NAME, LOOPS.LOOP_NAME