SQL Server中的日期和时间操作 [英] Date and time manipulation in SQL Server

查看:111
本文介绍了SQL Server中的日期和时间操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在做一个项目,我几乎要完成它,但是在报告阶段我却很忙.就是这样该软件(我正在研究的项目)会生成报告.我正在使用的报表服务是Microsoft Report Viewer,我想选择并显示上个月购买的所有客户(从单个表到报表).记住该报告将每月生成.

Hi everybody, I am working on some project and I am almost finishing it but in the reporting phase I stacked. It is like this. The software (the project that I am working on) generates a report. The reporting service that I am using is Microsoft Report Viewer and I want to select and display all the customers that purchased items last month, from a single table into the report. Remember the report is going to be generated every month.

推荐答案

redietlove写道:
redietlove wrote:

我要选择并显示上个月购买商品的所有客户

I want to select and display all the customers that purchased item last month



您需要在该表上编写一个SQL查询,该查询将始终返回上个月"的记录.因此,无论何时运行报告,您都可以获得今天30天的数据.

在查询中以所需方式设置此参数(上个月).
1.您要持续30天左右(必须是固定数量).

2.仅上个月.如果今天是3月13日,则结果集只需2月1日至28日.

因此,请使用适当的WHERE子句获取结果.
示例:



You need to write a SQL query on that table that will always return the records of ''last month''. Thus, whenever report is run, you get today-30 days data.

Set this (last month) parameter in your query the way you want.
1. You want last 30 days or so (has to be a fixed number).

2. Last month only. If today is 13th March, yet result set needs to be of just 1-28 Feb.

Accordingly, fetch the result with your appropriate WHERE clause.
Example:

Select 
   Id, Item, PurDate, Price 
From 
   PurTable 
Where 
   PurDate Between GetDate() AND (GetDate()-30)





redietlove写道:
redietlove wrote:

请记住,该报告将每月生成.

remember the report is going to be generated every month.


这部分可以由您的报表服务器处理.计划它生成并发送给用户.


This part can be handled by your report server. Schedule it to generate and send it to users.


这篇关于SQL Server中的日期和时间操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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