Skip to content
Advertisement

Insertion of dynamic values to specific colums using SQL

I’m trying to insert a new row into a table, but one column’s value insertion is dependent on a specific rule. So far I get an error because SQL doesn’t support my way and I have no idea what to do:

INSERT INTO RNFIL170
VALUES ('somthing1',0, 0, null,null,0, select max(RNFIL170.SEDER_HATZAGA)+1 from RNFIL170 , 0 , 0,1, 'somthing2');

How can I insert the max(RNFIL170.SEDER_HATZAGA)+1 into RNFIL170 ?

Advertisement

Answer

use INSERT INTO ... SELECT.. synxtax

Always specify the column list in the destination table

INSERT INTO RNFIL170 ( {column name list} )
SELECT 'somthing1',0, 0, null,null,0, max(RNFIL170.SEDER_HATZAGA)+1, 0 , 0,1, 'somthing2'
FROM   RNFIL170 ;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement