开发者

Advanced SQL Update query

开发者 https://www.devze.com 2023-02-12 04:05 出处:网络
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.

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开发者_StackOverflow 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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号