Tyler Miranda
Tyler Miranda

Reputation: 433

Advanced SQL Update query

I'm trying to create a sql update query for a stored procedure but I'm getting lost in trying to figure out how to to do it.

Here is what I'm trying do:

The table I'm wanting to update has 3 columns: product_item_id, rel_product_item_id, and sequence. This table is called "ProductRelationship".

I also have another table called ProductDetails. This table also contains a column called product_item_id as well as a column called "sku".

I want the user to be able input the sku number that updates the rel_product_item_id column with the corresponding product_item_id number from the ProductDetails table.

So on the front-end, the user is inputting a sku, but in the backend, the product_item_id number is getting updated in the database based on the sku the user entered.

Basically its cross-referencing the sku number on the details table, finding the appropiate product item id number and inserting that id number in the table instead of the user-inputted sku number.

Upvotes: 1

Views: 2656

Answers (1)

Joe Stefanelli
Joe Stefanelli

Reputation: 135808

update ProductRelationship
    set rel_product_item_id = (select product_item_id 
                                   from ProductDetails 
                                   where sku = @UserInput)
    where product_item_id = @ValueSetOnPage

Upvotes: 1

Related Questions