--Declaring the required variables
DECLARE @fromdate DATETIME
DECLARE @todate DATETIME
SET @fromdate = '2010-01-01'
SET @todate = '2010-01-10'
--Query to fetch all the dates between two given date
;WITH tmpinfo(tmpdt) AS
(SELECT @fromdate
UNION ALL
SELECT tmpdt + 1
FROM tmpinfo
WHERE tmpdt < @todate)
SELECT * FROM tmpinfo OPTION (MAXRECURSION 0);
Thank you! It is really useful
ReplyDeleteIts really very useful to me
ReplyDeletePerfect. Thanks!
ReplyDeleteGOOD ONE
ReplyDeleteGood. Found a simple and useful query here
ReplyDeleteMySQL reports about syntax error:
ReplyDelete[ERROR in query 1] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--Declaring the required variables
DECLARE @fromdate DATETIME
DECLARE @todate ' at line 1
[ERROR in query 2] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH tmpinfo(tmpdt) AS
(SELECT @fromdate
UNION ALL
SELECT tmpdt + 1
FROM tmp' at line 1
Well this query is for SQL server not MySQL
ReplyDeletePERFECT! I have been looking for something like this for days.
ReplyDeleteThis is symply what I was looking for. THANK YOU!!!
ReplyDeleteYou have a spelling error in your page title. Should be Technology, not Techonology.
ReplyDeleteThnaks to point out that...
DeleteAwesome. I was searching for something like this.
ReplyDelete