RT,比如
where 有大于2012-1-1 and 小于 2012-1-5 的条件,那么
返回结果类似于下面:
1.2012-1-2
2.2012-1-3
3.2012-1-4
肿么办,少年们??
CREATE FUNCTION GET_DATE(@BDATE DATETIME,@EDATE DATETIME) RETURNS @RE TABLE(ODATE DATETIME) AS BEGIN DECLARE @DATE DATETIME SET @DATE = DATEADD(DAY,1,@BDATE) WHILE DATEDIFF(DAY,@DATE,@EDATE)>0 BEGIN INSERT INTO @RE SELECT @DATE SET @DATE = DATEADD(DAY,1,@DATE) END RETURN END SELECT * FROM dbo.GET_DATE('2012-1-1',' 2012-1-5')