why update function cant related 2 table?

gholamreza rezaie 61 Reputation points

I have 2 table which first is header of Commodity purchase information and second is Information on the purchase of goods. in second table i have fee of my goods and I need to change fee of goods of in some number of first table for example update fee from first table which date of second table between 01.01.2022 an 02.02.2021

first and second table are one form that first is header of purchase and second is item of my purchase

do you think is it possible ?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
9,087 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Naomi 6,571 Reputation points

    I suggest you to first try as select statement to see if you can create a select statement of what the fee would be. Turning select statement into update is usually not hard, but it always helps to first try a SELECT to see the result before the actual update.

  2. LiHong-MSFT 9,986 Reputation points

    Hi @gholamreza rezaie
    Since the information you provided is not enough, I can only guess that you might to UPDATE using JOIN OR CTE.
    Please refer to these two articles : Inserts and Updates with CTEs in SQL Server (Common Table Expressions) and SQL Server UPDATE JOIN
    If not helpful ,still recommend you share us your table structure (CREATE TABLE …) and some sample data(INSERT INTO …) along with your expected result.

    Best regards,