如何在sqlserver 2005中显示按月,按年wisec数据 [英] how display month wise ,year wisec data in sqlserver 2005

查看:193
本文介绍了如何在sqlserver 2005中显示按月,按年wisec数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
如何从数据库获取按月和按年的报告
我有一天的想法
该代码是
从tbl1选择* where slipdate =''01/24/2011''

有人给我一些例子....

hello everybody
how to get month wise and year wise report from database
i have idea on day wise
that code is
select * from tbl1 where slipdate=''01/24/2011''

anybody give me some examples....

推荐答案

你好,亲爱的,

您还可以按年和按月获取数据.

要获取按年统计的数据,您必须获取单据的年和月部分,然后设置所需的年或月以过滤记录.

要获取日期的月份和年份,可以使用以下代码

从tbl1中选择*,其中convert(bigint,datepart(yy,slipdate))= 2011

下面的代码用于获取每月的报告.
从tbl1中选择*,其中convert(bigint,datepart(mm,slipdate))= 1
一月是这里1
Feb = 2,依此类推.
Hello Dear,

You can get the data year wise and month wise also.

To get the year wise data you have to get the year part and month part of the slipdate and then set your desired year or month to filter the record.

To get the month and the year of the slipdate you can use the below code

select * from tbl1 where convert(bigint, datepart(yy,slipdate))=2011

below code is to get month wise report.
select * from tbl1 where convert(bigint, datepart(mm,slipdate))=1
here january is 1
Feb=2 and so on.


查看 SQL DATEPART [ ^ ]函数-它可以向您返回月份或年份数据库中日期的一部分.然后,您要做的就是对照您感兴趣的报告日期范围检查它们.
Look at the SQL DATEPART[^] function - it can return you the month, or year section of a date in the database. Then all you have to do is check them against the reporting date range you are interested in.


这篇关于如何在sqlserver 2005中显示按月,按年wisec数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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