我将只给出SQL中的月份和年份,我需要从一年中开始日期到结束日期 [英] I will give only Month and year in SQL,I need start Date to End Date month of year
本文介绍了我将只给出SQL中的月份和年份,我需要从一年中开始日期到结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将只给出SQL中的月份和年份,我需要开始日期到结束日期年份
例如
我将给出SQl月'05'年'2014'
我需要从本月开始到结束日期
01-05-2014至31-05-2014
请帮我
I will give only Month and year in SQL,I need start Date to End Date month of year
For Example
I will give SQl Month '05' Year '2014'
I Need Start Start to End Date for this month
01-05-2014 to 31-05-2014
pls help me
推荐答案
DECLARE @Month int
DECLARE @Year int
set @Month = your Month
set @Year = your Year
select DATEADD(month,@Month-1,DATEADD(year,@Year-1900,0))
select DATEADD(day,-1,DATEADD(month,@Month,DATEADD(year,@Year-1900,0)))
DECLARE @Month int
DECLARE @Year int
Declare @TempStartDate Datetime, @TempEndDate Datetime
set @Month = 5
set @Year = 2014
select @TempStartDate= DATEADD(month,@Month-1,DATEADD(year,@Year-1900,0))
select @TempEndDate= DATEADD(day,-1,DATEADD(month,@Month,DATEADD(year,@Year-1900,0)))
SELECT [Date] = DATEADD(Day,Number,@TempStartDate)
FROM master..spt_values
WHERE Type='P'
AND DATEADD(day,Number,@TempStartDate) <= @TempEndDate
如果你得到了你想要的,那么点击接受解决方案。
If you got exactly what you want then click accept solution.
这篇关于我将只给出SQL中的月份和年份,我需要从一年中开始日期到结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文