Shafi ullah
Shafi ullah

Reputation: 75

insert data through date&time fom one table to another

i have the following query,

INSERT INTO Table[B] SELECT * FROM Table[A] WHERE (date between '2006-03-01 00:00:00' and '2006-05-31 23:59:59' and hour(date) between 5pm and 9am );

but it is not working .

actually i want to insert values form A to B having time 05pm to 09am

any solution please .

Upvotes: 1

Views: 38

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270421

I would expect something like this:

INSERT INTO TableB (col1, col2, . . .)
    SELECT col1, col2, . . .
    FROM TableA
    WHERE date >= '2006-03-01' AND date < '2006-06-01' AND
          (hour(date) < 9 OR hour(date) > 17);

Notes:

  • Explicitly list the columns when doing insert.
  • Explicitly list the columns where the values are from.
  • The date comparisons are simplified by using >= and <.

Upvotes: 1

Related Questions