Muhammad Kashif Muhammad Kashif - 2 years ago 97
SQL Question

How to insert date in to the copy Table in MySQL

I have to three tables (stock,trans and sales). I copy the stock Table into the trans using

insert into trans (idProduct,product_name,product_size,product_qty,details,product_price)select idProduct,product_name,product_size,product_qty,details,product_price from stock WHERE idProduct = '" + id + "'

And also copy table values to trans to sales using

insert into sales(idProduct,product_name,Product_size,qty,product_price) select idProduct,product_name,Product_size,qty,product_price from trans

Now I want to insert the current date in to the trans table particular row's cell.


Answer Source

Try using NOW() and doing it in the first insert.

insert into trans (idProduct,product_name,product_size,product_qty,details,product_price,particular_col)
select idProduct,product_name,product_size,product_qty,details,product_price,now() 
from stock WHERE idProduct = '" + id + "'

I've add to the list of column particular_column , place it in the right place with it right name, same goes for NOW()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download