如何将SQL查询的输出插入临时表中?(How to insert the output of a SQL Query into a temporary table?)
我正在使用SQL Server 2012,并且想要使用T-SQL执行以下操作:
创建一个临时表(我们称它为
#temptable
)。使用
SELECT
语句将位于现有数据库中的表的值插入到#temptable
。编写一个将查询
#temptable
的SELECT
语句。我已经尝试了以下,但它似乎语法不正确,或许我试图做的是不允许的。
USE MyDatabase CREATE TABLE #temptable GO INSERT INTO #TempTable SELECT [Col A], [Col B], [Col C] FROM MYLIST WHERE [MONTH OF STAY] = '2018-03-01' AND [Property] = 'ABC' SELECT * FROM #temptable
我如何向前迈进?
I am using SQL Server 2012 and I want to perform the following operations using T-SQL:
Create a temporary table (let's call it
#temptable
).Insert values from tables located in an existing database into
#temptable
using aSELECT
statement.Write a
SELECT
statement that will query the#temptable
.I have tried the following but it seems the syntax is not correct or perhaps what I am trying to do is not allowed.
USE MyDatabase CREATE TABLE #temptable GO INSERT INTO #TempTable SELECT [Col A], [Col B], [Col C] FROM MYLIST WHERE [MONTH OF STAY] = '2018-03-01' AND [Property] = 'ABC' SELECT * FROM #temptable
How do I move forward with this?
原文:https://stackoverflow.com/questions/48474513
最满意答案
使用以前的公式,我将使用以下内容:
=SUMPRODUCT((LEFT(TEXT(C$8,"mmm"),3)=LEFT($O$3:$O$12,3))*(DAY(C$8)=--RIGHT($O$3:$O$12,2)))
基本上,如果月份的前三个字母匹配且日期的天数匹配,则公式将返回值1,对于Excel数学,该值等于true。 所有其他结果应该返回0.还必须在列表中没有重复的假日日期,否则公式将返回大于1的值。但是也有方法,但这是一个后续问题。
Working off your previous formula I would use something along the lines of the following:
=SUMPRODUCT((LEFT(TEXT(C$8,"mmm"),3)=LEFT($O$3:$O$12,3))*(DAY(C$8)=--RIGHT($O$3:$O$12,2)))
Basically the formula will return the value of 1 which is equivalent to true for excel math if the first three letters of the month match and the date's day number match. All other results should return 0. It is also imperative that you do not have duplicate holiday dates in your list or the formula will return a value greater than 1. But there are ways around that too, but that is a follow up question.
相关问答
更多-
这是我如何处理这个问题。 创建一个函数,该函数将采用RECURRENCESTARTDATE,RECURRENCEENDDATEONLY,RECURRENCETYPE,RECURRENCEINTERVAL,RECURRENCEDAYOFWEEKMASK,RECURRENCEDAYOFMONTH,RECURRENCEINSTANCE,RECURRENCEMONTHOFYEAR等参数。 然后这个函数将从开始日期开始循环,并且对于永远迭代,它将递增值,直到日期>今天或日期> RECURRENCEENDDATEONL ...
-
Excel - 根据假期列表突出显示时间表上的假日(Excel - Highlight holidays on timesheet based on list of holidays)[2022-03-23]
使用以前的公式,我将使用以下内容: =SUMPRODUCT((LEFT(TEXT(C$8,"mmm"),3)=LEFT($O$3:$O$12,3))*(DAY(C$8)=--RIGHT($O$3:$O$12,2))) 基本上,如果月份的前三个字母匹配且日期的天数匹配,则公式将返回值1,对于Excel数学,该值等于true。 所有其他结果应该返回0.还必须在列表中没有重复的假日日期,否则公式将返回大于1的值。但是也有方法,但这是一个后续问题。 Working off your previous formu ... -
就我所知,Java中没有什么可靠的。 这也是有道理的,这种信息对变化非常敏感。 硬编码会使你的代码潜在地破坏每一个Java更新,这可能导致大量的维护和兼容性问题。 目前,在Java SE中,时区已被硬编码/维护,甚至单独已经导致了许多错误 。 而是使用一个公共的Web服务。 例如http://www.bank-holidays.com 本网站通知您银行(以及若干国家的证券交易所和学校假期)由于宗教或公共活动而关闭的所有日子。 重大事件(选举,宣布罢工,展览会,节日,体育赛事...)也被列出。 我们的免费服务 ...
-
我认为你不是试图将列表子集化,而是timeDate在该列表的元素中使用类timeDate的向量 。 这可以简单地完成: Biz_Seq <- lapply(Date_List, function(days) days[isBizday(days, Holidays)]) I think you're not trying to subset a list but rather the vectors of class timeDate in the elements of that list. This ...
-
该错误是因为当您实际只需要id时,您将获得hr.employee对象。 尝试改变: ('employee_id','=',employee_id)] 至 ('employee_id','=',employee_id.id)] sheet是一个整数,您必须首先浏览该对象,然后访问total_attendance 。 尝试: if sheet: sheet_obj=self.pool.get('hr_timesheet_sheet.sheet').browse(cr, uid, sheet, co ...
-
public static bool IsHoliday(this DateTime date) { ConnectionStringSettings myConnectionString = ConfigurationManager.ConnectionStrings["System.Properties.Settings.ConnectionString"]; SqlConnection mySqlConnection = new SqlConnection(myConnectionString.Con ...
-
由于周定义可能因公司不同而不同(一周开始时,一年的第一周是什么),我建议在其他地方在周开始和周末添加一行。 然后输入函数=NETWORKDAYS([Your week start date], [Your week end date], $A$29:$A:$40 where your holidays are)*8 Since week definitions can vary from company to company (when a week starts, what the first week ...
-
列表是比较日期和假日集合的最佳收藏方法吗?(Is List the best collections method for comparing a date to a collection of holidays?)[2023-04-19]
在列表中搜索是O(n):你必须迭代每个元素,直到找到匹配的元素。 如果列表按日期排序,则可以使用Collections.binarySearch() ,这将使进程O(log(n))(因此,除非列表非常小,否则无关紧要) 。 您也可以使用TreeSet来保持假日排序,并允许在O(log(n))时间内进行搜索。 或者您可以使用HashSet,这将使搜索O(1)(常量时间),但不会保持其元素排序。 Searching in a list is O(n): you have to iterate through e ... -
我已经知道我哪里出错了。 if (date.getFullYear() == d.getFullYear() && date.getMonth() == d.getMonth() && date.getDate() == d.getDate()) { return [true, 'holiday', result[i][3]]; } else { ...
-
用于计算excel中2个日期之间的假日数的公式(Formula to count the number of holidays between 2 dates in excel)[2022-05-03]
假设您还有名为“date1”和“date2”的范围,这将起作用。 这是包容性的,例如,如果date1 = 1/1/11,它将计算新年。 如果您不想要,请删除“=”。 =SUMPRODUCT((holidays>=date1)*(holidays<=date2)) Assuming you also have ranges named "date1" and "date2" this will work. It's inclusive, e.g., it will count New Years Day i ...