views:

46

answers:

1

I have an order table in MySQL database, having a field/column which stores the date timestamp of when the order was placed.

I need to calculate when the order must be shipped. I could probably figure out how to write a function to calculate the ship date and call that when ever needed but I think, not sure it may make more sense to have the shipdate as a calculated column.

That being said, I have never used a stored procedure or created a calculated field. The later I think would be best but again not sure. I used to make calculated field all the time in FMP but I've gotten away from that program.

A: 

I would do it as a view. This is basically a select statement where one result column is the ship date. You can add other relevant columns too. Any app with access to the database can then access the view the same way as ordinary tables.

If your table looked like:

create table orders(id INTEGER PRIMARY KEY AUTO_INCREMENT,
                    order_date DATETIME);                                                                      

and you always shipped 3 days after, you could use:

create view order_view as 
  select id, 
         order_date, 
         order_date + INTERVAL 3 DAY as ship_date 
  from orders;

The select statement can be made as complex as needed. Then, you just read order_view in any application, as if it were an ordinary table.

Matthew Flaschen
this could be cool I'll play around with this and see if this fits the bill. are there an caveats to using this
mcgrailm