简体   繁体   English

用动态日期命名临时表

[英]Naming a Temp Table with a Dynamic Date

Is there a way to Name a temp table with a variable date? 有没有一种方法可以命名具有可变日期的临时表?

For Example: 例如:

DECLARE @SomeDate datetime = '12/31/2016'

Select * 
into #?? 
from Table

The end result I'm looking for is #201612 我正在寻找的最终结果是#201612

In SQL Server and possibly others, temp tables (but not global temp tables) are only visible to the session. 在SQL Server和其他可能的数据库中,临时表(而不是全局临时表)仅对会话可见。 Multiple sessions can create the temp tables with the same name and they don't interfere with each other. 多个会话可以创建具有相同名称的临时表,并且它们不会互相干扰。 So, possibly all you need is a fixed name. 因此,您可能需要的只是一个固定名称。

Check this for more info: Scope of temporary tables in SQL Server 检查此以获得更多信息: SQL Server中临时表的范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM