sql >> Database teknologi >  >> RDS >> Sqlserver

Indsæt variabel CTE i tabel

Prøv dette

with CTE as 
    (SELECT       
      a.Title 
     ,a.Id
  FROM
       TableA
     )
    ,CTE2 as 
    (SELECT  
      b.Title
     ,b.Id   
  FROM
       TableB
    )
    INSERT INTO @myData  --- insert statement goes here after CTE

    Select * From CTE    
    union all    
    Select * From CTE2

    Select  ROW_NUMBER() OVER(ORDER BY GetDate() DESC) AS RowId, x.* 
    From @myData x
    order by x.Id desc


  1. Hvad er SQLite

  2. at finde den 3. højeste løn i mysql uden grænse

  3. Den officielle Microsoft Access Tech Blog er nu online!

  4. sum pris for børn i anden tabel mysql