Home>

I am developing with Visual Basic, but I am stumbling at the point of registering with SQL Server.

I don't know how to register data that is not on the screen. ..
Applicable source code
Values ​​are set in the tables below.
Current table: id (primary key) | SDNO | Date
Table I want to realize: id (primary key) | SDNO | SDNAME | SDCD | Date
I want to set a value to a table item that I want to realize.
SDNAME and SDCD are registered in different tables with SDNO as the primary key.
I don't know how to set the value. ..
The explanation is very difficult to understand, but I would appreciate your favor.
Supplementary information (FW/tool ​​version, etc.)

Visual Studio2017, SQL Server

  • Answer # 1

    As mentioned in the postscript/correction request, it is impossible to add columns at the time of registration with SQL.

    Add columns to TABLE

    Please refer to the above URL and add the synonymous SDNAME and SDCD of Table B.

    This is the main subject, but I will attach a URL about how to use the data of other tables for registration.
    (Please read through.)

    INSERT-SELECT

    In this case, it is as follows.
    SDNO and Date are described with the recognition that they have them.

    // The original SDNO and Date are "PARAM_SDNO" and "PARAM_Date".
    INSERT INTO TABLE_A (SDNO,
                         SDNAME,
                         SDCD,
                         Date)
                  SELECT PARAM_SDNO,
                         TABLE_B.SDNAME
                         TABLE_B.Date,
                         PARAM_Date
                    FROM TABLE_B
                   WHERE TABLE_B.SDNO = PARAM_ SDNO;

  • Answer # 2

    Thank you for responding to difficult questions!
    It was very helpful!

Related articles