SQL查询结果如何插入临时表? [英] How SQL query result insert in temp table?
本文介绍了SQL查询结果如何插入临时表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 SQL 查询 (SQL Server) 并且它生成报告,我想将该确切报告存储在临时表中,以便我以后可以使用它.现在的问题是我需要先创建临时表然后将SQL查询结果存储到其中,还是有什么方法可以动态创建表并存储查询结果?
I have a SQL query (SQL Server) and it generate reports, I want to store that exact report in temp table so I can play with it later. Now question is do I need to create temp table first and then store SQL query result into it, or is there any way to dynamically create table and store query result?
推荐答案
看SELECT INTO.这将为您创建一个新表,如果您愿意,可以通过在表名前加上井号 (#) 来创建临时表.
Look at SELECT INTO. This will create a new table for you, which can be temporary if you want by prefixing the table name with a pound sign (#).
例如,您可以:
SELECT *
INTO #YourTempTable
FROM YourReportQuery
这篇关于SQL查询结果如何插入临时表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文