如何在查询中创建月份名而不是月份整数值 [英] How to make monthname instead of month integer value in a query

查看:62
本文介绍了如何在查询中创建月份名而不是月份整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,

我尝试了以下指定的代码。两者都给出了几乎相同的结果。我需要MonthName而不是eMonth列值作为相同的排序顺序。 (因为我想将这个DataSet用于网格的DataSource。



我写下面的结果。



 eYear eMonth ReceiptTotal PaymentTotal< br /> 
------------------------------- -------------------< br />
2015 4 25,000.00 0.00< br />
2015 5 500.00 0.00< br />
2015 12 50,000.00 0.00< br />
2016 1 5,000.00 0.00< br />
2016 6 41,000.00 9,154.50< br />
======= ===========================================< br />
< br />
(我需要得到如下所述的结果。)< br />
< br />
eYear eMonth ReceiptTotal PaymentTotal< br />
---------------------------------------------- ---< br />
2015年4月25,000.00 0.00< br />
2015年5月500.00 0 .00< br />
2015年12月50,000.00 0.00< br />
2016年1月5,000.00 0.00< br />
2016年6月41,000.00 9,154.50< br />
= ================================================





这意味着我只需要用它的月份名称替换整月,就像我上面显示的排序顺序一样。



先谢谢亲爱的专家。



我的尝试:



SELECT年份(edate)作为eYear,Month(edate)作为eMonth,Sum(收据)作为ReceiptTotal,Sum(payment)作为PaymentTotal FROM条目& DataFilterCondition& GROUP BY Year(edate),Month(edate)



SELECT Year(edate)as eYear,Val(Format(edate,'m'))作为eMonth, Sum(收据)作为ReceiptTotal,Sum(payment)作为PaymentTotal FROM条目& DataFilterCondition& GROUP BY Year(edate),Val(格式(edate,'m'))

解决方案

正如谢尔盖所​​说,你可能应该使用日期数据类型,但是如果你只需要一个月号就可以使用这样的东西将它转换成月份名称:



 SELECT DateName(M,DateAdd(M) ,MonthNumber,-1))





如果你确实有一个日期字段,你可以简单地使用DateName函数:



  SELECT  DateName(M,DateField)


Sir,
I tried both codes as below specified. Both r giving almost same result. I need MonthName instead of eMonth column values as the same sorting order. (Because I want to use this DataSet for grid's DataSource.

I am writing below it's result.

eYear    eMonth      ReceiptTotal     PaymentTotal<br />
--------------------------------------------------<br />
2015          4         25,000.00             0.00<br />
2015          5            500.00             0.00<br />
2015         12         50,000.00             0.00<br />
2016          1          5,000.00             0.00<br />
2016          6         41,000.00         9,154.50<br />
==================================================<br />
<br />
(And I need to get the result as below mentioned.)<br />
<br />
eYear   eMonth      ReceiptTotal     PaymentTotal<br />
-------------------------------------------------<br />
2015    April          25,000.00             0.00<br />
2015    May               500.00             0.00<br />
2015    December       50,000.00             0.00<br />
2016    January         5,000.00             0.00<br />
2016    June           41,000.00         9,154.50<br />
=================================================



Which means just I need to replace only the integer month with it's month name as the same sorting order as I shown above.

Thanks in advance dear experts.

What I have tried:

SELECT Year(edate) As eYear, Month(edate) As eMonth, Sum(receipt) as ReceiptTotal, Sum(payment) as PaymentTotal FROM entries " & DataFilterCondition & " GROUP BY Year(edate), Month(edate)

SELECT Year(edate) As eYear, Val(Format(edate,'m')) As eMonth, Sum(receipt) as ReceiptTotal, Sum(payment) as PaymentTotal FROM entries " & DataFilterCondition & " GROUP BY Year(edate), Val(Format(edate,'m'))

解决方案

As Sergey says, you probably should be using date datatypes, but if you just have the month number you can use somethign like this to convert it to the month name:

SELECT DateName(M, DateAdd(M, MonthNumber, -1))



If you do actually have a date field, you can simply use the DateName function:

SELECT DateName(M, DateField )


这篇关于如何在查询中创建月份名而不是月份整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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