日期:2014-05-18  浏览次数:20438 次

根据参数ny(年月)获取指定年月的天数,该怎么做呢
根据参数ny(年月)获取指定年月的天数,该怎么做呢

------解决方案--------------------
SQL code
declare @ny int
set @ny=201206

select datepart(dd,dateadd(dd,-1,dateadd(m,1,ltrim(@ny)+'01')))

------解决方案--------------------
SQL code

DECLARE @N VARCHAR(10) = '2012'
DECLARE @Y VARCHAR(10) = '06'

SELECT CONVERT(VARCHAR(10),DATEADD(DAY,number,@N + '-' + @Y + '-' + '01'),23) AS Date FROM master..spt_values WHERE type = 'P' AND DATEADD(DAY,number,@N + '-' + @Y + '-' + '01') < CONVERT(VARCHAR(8),DATEADD(MONTH,1,@N + '-' + @Y + '-' + '01'),21) + '01' 

Date
2012-06-01
2012-06-02
2012-06-03
2012-06-04
2012-06-05
2012-06-06
2012-06-07
2012-06-08
2012-06-09
2012-06-10
2012-06-11
2012-06-12
2012-06-13
2012-06-14
2012-06-15
2012-06-16
2012-06-17
2012-06-18
2012-06-19
2012-06-20
2012-06-21
2012-06-22
2012-06-23
2012-06-24
2012-06-25
2012-06-26
2012-06-27
2012-06-28
2012-06-29
2012-06-30