INSERT INTO ... SELECT question

2002-11-14 Thread Greg Macek
Hello,

I recently stumbled upon the INSERT INTO..SELECT abilities. Basically
what I'm doing is archiving records into another table before deleting
them (inventory information). However, I'd like to have the archive
table to have one more field than the original table: a date_archived
function. So, for example if the tables looked like this: (quite
simplified)

Original:

carton_id
item_id
qty
status
date_recd

Archive

carton_id
item_id
qty
status
date_recd
date_archived *(new field)

Can I have the SQL query have a NOW() in there to insert today's date
when running this ? 

INSERT INTO archive
(carton_id,item_id,qty,status,date_recd,date_archived) 
SELECT carton_id,item_id,qty,status,date_recd, NOW() FROM original

Would this work? I'd like to know upfront before basing my code around
this or whether or not I'll have to track how many records are going
into the new table and manually updating the field. Thanks.

- Greg




-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: INSERT INTO ... SELECT question

2002-11-14 Thread Greg Macek
Well, amazingly enough, it works great! I found a test box to try it on
first before implementing this on the production box. This will
definitely make life easier... 

On Thu, 2002-11-14 at 10:14, gerald_clark wrote:
 Did you try it?
 Did it work?
 
 Greg Macek wrote:
 
 Hello,
 
 I recently stumbled upon the INSERT INTO..SELECT abilities. Basically
 what I'm doing is archiving records into another table before deleting
 them (inventory information). However, I'd like to have the archive
 table to have one more field than the original table: a date_archived
 function. So, for example if the tables looked like this: (quite
 simplified)
 
 Original:
 
 carton_id
 item_id
 qty
 status
 date_recd
 
 Archive
 
 carton_id
 item_id
 qty
 status
 date_recd
 date_archived *(new field)
 
 Can I have the SQL query have a NOW() in there to insert today's date
 when running this ? 
 
 INSERT INTO archive
 (carton_id,item_id,qty,status,date_recd,date_archived) 
 SELECT carton_id,item_id,qty,status,date_recd, NOW() FROM original
 
 Would this work? I'd like to know upfront before basing my code around
 this or whether or not I'll have to track how many records are going
 into the new table and manually updating the field. Thanks.
 
 - Greg
 
 
 
 
 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)
 
 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail 
[EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
 
 
   
 
 



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: INSERT INTO ... SELECT question

2002-11-14 Thread Matthew Baranowski
Hey Greg:

A slightly easier way to do this is to use a timestamp field. Timestamp is
just a standard mysql data type. When a record is added, it records the
current time. When a record is updated, the timestamp field will be set to
the time of the update.

http://www.mysql.com/doc/en/DATETIME.html
The TIMESTAMP column type provides a type that you can use to automatically
mark INSERT or UPDATE operations with the current date and time. If you have
multiple TIMESTAMP columns, only the first one is updated automatically.

Thanks,

Matt

Matthew P Baranowski
Data Manager, Office of Educational Assessment
University of Washington

- Original Message -
From: Greg Macek [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, November 14, 2002 8:06 AM
Subject: INSERT INTO ... SELECT question


 Hello,

 I recently stumbled upon the INSERT INTO..SELECT abilities. Basically
 what I'm doing is archiving records into another table before deleting
 them (inventory information). However, I'd like to have the archive
 table to have one more field than the original table: a date_archived
 function. So, for example if the tables looked like this: (quite
 simplified)

 Original:

 carton_id
 item_id
 qty
 status
 date_recd

 Archive

 carton_id
 item_id
 qty
 status
 date_recd
 date_archived *(new field)

 Can I have the SQL query have a NOW() in there to insert today's date
 when running this ?

 INSERT INTO archive
 (carton_id,item_id,qty,status,date_recd,date_archived)
 SELECT carton_id,item_id,qty,status,date_recd, NOW() FROM original

 Would this work? I'd like to know upfront before basing my code around
 this or whether or not I'll have to track how many records are going
 into the new table and manually updating the field. Thanks.

 - Greg




 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail
[EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: INSERT INTO ... SELECT question

2002-11-14 Thread Greg Macek
Thanks for the tip! Looks like I can change my date_archived field to
timestamp(8), since all I care about for this is the date information
(actual time is useless to me). My sql query all of a sudden got a lot
simpler. Thanks again for the help!


On Thu, 2002-11-14 at 11:07, Matthew Baranowski wrote:
 Hey Greg:
 
 A slightly easier way to do this is to use a timestamp field. Timestamp is
 just a standard mysql data type. When a record is added, it records the
 current time. When a record is updated, the timestamp field will be set to
 the time of the update.
 
 http://www.mysql.com/doc/en/DATETIME.html
 The TIMESTAMP column type provides a type that you can use to automatically
 mark INSERT or UPDATE operations with the current date and time. If you have
 multiple TIMESTAMP columns, only the first one is updated automatically.
 
 Thanks,
 
 Matt
 
 Matthew P Baranowski
 Data Manager, Office of Educational Assessment
 University of Washington
 
 - Original Message -
 From: Greg Macek [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, November 14, 2002 8:06 AM
 Subject: INSERT INTO ... SELECT question
 
 
  Hello,
 
  I recently stumbled upon the INSERT INTO..SELECT abilities. Basically
  what I'm doing is archiving records into another table before deleting
  them (inventory information). However, I'd like to have the archive
  table to have one more field than the original table: a date_archived
  function. So, for example if the tables looked like this: (quite
  simplified)
 
  Original:
 
  carton_id
  item_id
  qty
  status
  date_recd
 
  Archive
 
  carton_id
  item_id
  qty
  status
  date_recd
  date_archived *(new field)
 
  Can I have the SQL query have a NOW() in there to insert today's date
  when running this ?
 
  INSERT INTO archive
  (carton_id,item_id,qty,status,date_recd,date_archived)
  SELECT carton_id,item_id,qty,status,date_recd, NOW() FROM original
 
  Would this work? I'd like to know upfront before basing my code around
  this or whether or not I'll have to track how many records are going
  into the new table and manually updating the field. Thanks.
 
  - Greg
 
 
 
 
  -
  Before posting, please check:
 http://www.mysql.com/manual.php   (the manual)
 http://lists.mysql.com/   (the list archive)
 
  To request this thread, e-mail [EMAIL PROTECTED]
  To unsubscribe, e-mail
 [EMAIL PROTECTED]
  Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
 
 



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: INSERT INTO ... SELECT question

2002-11-14 Thread Paul DuBois
At 11:15 -0600 11/14/02, Greg Macek wrote:

Thanks for the tip! Looks like I can change my date_archived field to
timestamp(8), since all I care about for this is the date information
(actual time is useless to me). My sql query all of a sudden got a lot
simpler. Thanks again for the help!


TIMESTAMP values are always stored to the full 14 digits.  The 8
affects display only, though that appears to be exactly what you want.




On Thu, 2002-11-14 at 11:07, Matthew Baranowski wrote:

 Hey Greg:

 A slightly easier way to do this is to use a timestamp field. Timestamp is
 just a standard mysql data type. When a record is added, it records the
 current time. When a record is updated, the timestamp field will be set to
 the time of the update.

 http://www.mysql.com/doc/en/DATETIME.html
 The TIMESTAMP column type provides a type that you can use to automatically
 mark INSERT or UPDATE operations with the current date and time. If you have
 multiple TIMESTAMP columns, only the first one is updated automatically.

 Thanks,

 Matt

 Matthew P Baranowski
 Data Manager, Office of Educational Assessment

  University of Washington



-
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php