why update function cant related 2 table?

gholamreza rezaie 61 Reputation points
2022-02-14T08:32:52.79+00:00

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 ?
174032-update-for-two-table.jpg

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,682 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,625 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Naomi Nosonovsky 7,856 Reputation points
    2022-02-15T02:35:48.057+00:00

    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.

    0 comments No comments

  2. LiHong-MSFT 10,046 Reputation points
    2022-02-15T07:38:28.797+00:00

    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,
    LiHong

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.