SQL查询:在Temp Table中每月提取数据 [英] SQL Query : Pull data for every month in Temp Table

查看:225
本文介绍了SQL查询:在Temp Table中每月提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

以下是我将数据插入临时表(#tmpA)3个月后的查询。 



Hi, 
Below is the query where I am inserting data into temp table (#tmpA) going back 3 months. 

将数据插入#tmpA后,我将在同一商店程序中的另一个查询中使用此临时表。以下是部分查询: 
$


Once the data is inserted into #tmpA, I will using this temp table in another query in the same store procedure. Below is the part of Query : 

我的问题是,我可以逐个月份这样做,比如先运行整个查询 从1月1日到1月31日,然后是2月1日到2月28日等。就像一个循环?或者任何其他选项。 

My Question here is, Can i do this month by month, like first run the whole query  from Jan 1 to Jan 31 and then Feb 1 to Feb 28 etc..Like a LOOP ? or any other options. 

推荐答案

如果您每月都这样做,Max_Createddatetime每月会有一个值。但如果这是你想要的,你可以改变PARTITION BY子句来包括


convert(char(6),Createddatetime,112)

If you do it month by month, Max_Createddatetime will have one value per month. But if this is what you want, you could change the PARTITION BY clause to include
convert(char(6), Createddatetime, 112)

此格式为您提供YYYYMM,这对于每个月的分区很有用。

This format gives you YYYYMM which is good for partitioning per month.


这篇关于SQL查询:在Temp Table中每月提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆