Andres S
Andres S

Reputation: 471

Insert into....select query returning blank

I'm trying to execute the following command through straight sql execution and it runs fine without any errors but it's not actually working.

INSERT INTO log_inventory(CREATED_TIME, PRODUCT_ID, LOG_INV_CHANGE, LOG_INV_ACTION, LOG_INV_NUM_HISTORY, USER_ID)
SELECT now(), p.PRODUCT_ID, p.PRODUCT_INVENTORY, 'Manual Inventory Override', 0, 1
FROM product AS p WHERE p.PRODUCT_INVENTORY != 0;

The select query works because if I run that separately, it returns all the rows I need, but the insert portion doesn't work. Am I missing something?

Upvotes: 0

Views: 778

Answers (1)

iubema
iubema

Reputation: 349

Supposing the query has results, try this:

INSERT INTO log_inventory(CREATED_TIME, PRODUCT_ID, LOG_INV_CHANGE, LOG_INV_ACTION, LOG_INV_NUM_HISTORY, USER_ID)
(
    SELECT now(), p.PRODUCT_ID, p.PRODUCT_INVENTORY, 'Manual Inventory Override', 0, 1
    FROM product AS p 
    WHERE p.PRODUCT_INVENTORY != 0
);

Hope that helps

Upvotes: 1

Related Questions