0

Is it possible to INSERT the result of the following query into new table

SELECT
    O.[full name], 
    O.[EID], 
    O.[Loc],
    GL.*
FROM 
    [dbo].[team] O 
OUTER APPLY 
    [dbo].[fngetlocdetail] (O.[eWorkCity]) GL

As standalone it works but I cannot INSERT results these results into a new table. Please guide. Thanks

Eli
  • 2,538
  • 1
  • 25
  • 36
ANASI-Newbie
  • 111
  • 8

2 Answers2

3

Just use into:

select O.[full name], O.[EID], O.[Loc], GL.*
into #NewTable
from [dbo].[team] O outer apply
     [dbo].[fngetlocdetail](O.[eWorkCity]) GL;

You should specify the column names for GL. As @Prdp aptly points out, this will fail if the column names in GL duplicate one of the other names.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • This may throw error if `[dbo].[fngetlocdetail]` returns same column name as the ones present in column list. But the possibility is very less just a information to OP. – Pரதீப் Jan 14 '17 at 02:06
0

Did you try to use the Select Into statement?

SELECT 
    column_name(s)
INTO newtable [IN externaldb]
FROM table1;
Eli
  • 2,538
  • 1
  • 25
  • 36
GantTheWanderer
  • 1,255
  • 1
  • 11
  • 19