但它没有给我输出。 请告诉我哪里出错了 Hi alli have two combo box where i added all the months name's first 3 letters(e.g. Jan, Feb etc.)and another combo box which is having all the years from 2005-2012Now i wrote the below query to find the result between 2 months of a yearbut it's not giving me the output.Please tell me where i am going wrongselect DatePart(MM,FromDate) as Month,Sum(Amount) as Amount from SuppReport where DatePart(MM,FromDate) between DATEPART(MM,CAST('Jan'+ '2005' AS datetime) and DATEPART(MM,CAST('Dec'+ '2005' AS datetime)and CONVERT(VARCHAR(4),DateName(YEAR,FromDate))='2005' Group By DatePart(MM,FromDate) 在此查询中,我正在尝试将月份名称转换为月份号码。 但显示错误 In this query i am trying to convert month name to month number.but showing errorMsg 156, Level 15, State 1, Line 3Incorrect syntax near the keyword 'and'. 推荐答案 使用 DATEPART i nstead,请看这里: http://www.w3schools.com/sql/func_datepart.asp [ ^ ] ,你也应该使用数字月而不是'Feb'和'Apr'(你可以使用 DATEPART 函数)。Use DATEPART instead, see here : http://www.w3schools.com/sql/func_datepart.asp[^]and also you should use numeric months not 'Feb' and 'Apr' (you can do it with the DATEPART function). 这篇关于根据月份和年份获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-16 09:53