I have a query in SQL Server:
insert into [Sha1](
[IDTbl]
,[IDTbl_old]
,[IDold]
,[WordsAsl])
(SELECT [IDTbl]
,[IDTbl_old]
,[IDold]
,[WordsAsl]
FROM [Sha2])
How to solve this error:
Cannot insert the value NULL into column ‘IDTbl’, table ‘Sha1’; column
does not allow nulls. INSERT fails.
The other option besides just excluding those rows from your
SELECTthat containNULLis to use theISNULL()function to provide a default values instead ofNULL:Here I stipulated that should the
IDTblvalue fromdbo.Sha2beNULL, then theSELECTshould return 42 instead (and thus insert this value intodbo.Sha1instead ofNULL).