IBM i Global

IBM i 

A space for professionals working with IBM’s integrated OS for Power systems to exchange ideas, ask questions, and share expertise on topics like RPG and COBOL development, application modernization, open source integration, system administration, and business continuity.


#Power


#IBMi
#Power
 View Only
  • 1.  insert with subselect error SQL0412

    Posted Tue September 16, 2025 02:13 PM

    Hi, 

    why is this statement posting error: 

     . :   SQL0412       Severity . . . . . . . :   30   
     . :   Diagnostic                                    
                                                         
    Subselect with more than one result column not valid.

    insert into table2  (col1, col2)      
        values                  
          ( select        col1, col2                   
                                     from table1      
    )    ;                                              



    ------------------------------
    Michael Cramer
    ------------------------------


  • 2.  RE: insert with subselect error SQL0412

    Posted Tue September 16, 2025 02:20 PM

    Hi Michael,

    the statement should look like this:

    insert into table2 (col1, col2)      
      select col1, col2
      from table1; 

    The VALUES clause is only used, when you want to insert values from a list.

    insert into table2 (col1, col2)      
      values (
        (1, 2), -- 1st row with 2 values
        (3, 4), -- 2nd row ...
        (5, 6)  -- 3rd row ...
      );                                              

    HTH

    Daniel



    ------------------------------
    Daniel Gross
    #IBMChampion
    Senior Core Developer, Geis Group
    Pegnitz, Germany
    https://blog.qpgmr.de/
    ------------------------------



  • 3.  RE: insert with subselect error SQL0412

    Posted Tue September 16, 2025 02:41 PM

    Thank you Daniel, that worked! 



    ------------------------------
    Michael Cramer
    ------------------------------