0

I have Table Fields (Columns) like

ID
DATE

I want to insert the rows in above table in between date ranges

For Example:

If I given the date Range like 23/1/2014 to 25/1/2014

then row insertion result should be like this

   ID   |   DATES   

    1   |   23/1/2014

    2   |   24/1/2014

    3   |   25/1/2014

please provide me the solution in the form of Query not Stored procedure/Function

Kuldeep Jain
  • 8,409
  • 8
  • 48
  • 73
Yograj Sudewad
  • 343
  • 2
  • 9

3 Answers3

2

If you want to use generated range in one query then look to the solution of your problem How to get list of dates between two dates in mysql select query.

Community
  • 1
  • 1
DoNotArrestMe
  • 1,285
  • 1
  • 9
  • 20
0

Try this equivalent in MySQL. This works in SQL Serever but not tried in MySQL

Declare @date table(autoid int IDENTITY(1, 1),d date)
Declare @d datetime

set @d='20140123'

While @d<='20140125'
Begin
    Insert into @date values (@d)
    set @d=@d+1
End
Select autoid ,d as DateCol from @date
Damith
  • 1,982
  • 3
  • 28
  • 42
0

This Query will help to get all dates in between range. with that you can insert it in your table:

    select * from (select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
     (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
     (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
     (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
     (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
     (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
    where selected_date between '2012-02-10' and '2012-02-15'
murtaza.webdev
  • 3,523
  • 4
  • 22
  • 32