将连接的结果推送到新表中?

时间:2015-08-20 13:35:40

标签: sql sql-server-2008

SQL的新手,一直在搞乱它。我正在使用Microsoft SQL Management Studio 2008.我想知道是否有办法将SQL查询的结果推送到新表中?无论如何,谢谢你提前帮助!

编辑:很抱歉缺少查询人员,我的不好。

{{1}}

2 个答案:

答案 0 :(得分:2)

一个简单的方法是使用into语句。

select *
into #temptable
-- from sometable join someothertable on ...
-- where conditions

编辑:每个OP的查询

select t.*
into #temptable
from 
(SELECT *
FROM UnaData AS Una
FULL OUTER JOIN GCData AS GC
ON GC.[Bill Rate] = Una.[Bill Rate] AND
GC.[Employee Name] = Una.username AND
GC.Revenue = Una.[Bill Rate] * Una.[Hours] AND
GC.[Contract Number] = Una.[Project Code] AND
GC.[Job Category] = Una.[Cost Element] AND
GC.[Hours Billed] = Una.[Hours] 
WHERE Una.username IS NULL OR GC.[Employee Name] IS NULL
) t

您现在可以将整个查询视为表格t,然后您可以into #temptable插入order by。此外,当您选择into表格时,不应使用Error Process: com.myapp, PID: 1605 java.lang.NoClassDefFoundError: org.jivesoftware.smack.SmackConfiguration at com.quickblox.chat.QBChatService.setDebugEnabled(QBChatService.java:183) at com.myapp.ui.activities.SplashActivity.onCreate(SplashActivity.java:120) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) 。它已被删除。

答案 1 :(得分:-6)

您可以使用以下SQL查询:

//following line creates a new table with the same schema as 'table_name'

create table new_table_name as select * from table_name

insert into new_table_name select * from table_name;
相关问题