Thread: Re: Can I use variable to store sql data?

Re: Can I use variable to store sql data?

From
Bruno Wolff III
Date:
Please post questions to relevant lists. This question did not belong on
the patches list. I have moved the discussion to the general list.

Please don't reply to other threads to start new ones. This messes up the
archives and won't help people see your question.

On Mon, Oct 17, 2005 at 09:55:50 +0300,
  NosyMan <nosyman@gmail.com> wrote:
> Hi,
>
> The scenario:
> SELECT id_product FROM products WHERE product_code='PRD-030';
>
> Now I want to insert id_product into another table :
>
> INSERT INTO product_sales( id_product, sale_date)
> INSERT INTO product_sales( id_product, sale_date)
> INSERT INTO product_sales( id_product, sale_date)

You can do something like:
INSERT INTO product_sales values (
  (SELECT id_product FROM products WHERE product_code='PRD-030'),
  sales_date);

Also if id_product was just assigned a value from a sequence in the same
session, you could use the currval function to get its value.