Ordinary
Ordinary

Reputation: 45

Cannot insert the value NULL into column '', table column does not allow nulls. INSERT fails.Failed to execute following SQL block

I am getting following error when i execute following command. Can someone please help!

Cannot insert the value NULL into column '', table column does not allow nulls. INSERT fails.Failed to execute following SQL block

BEGIN
    Select @v_setting_val=setting_val from EGPL_PROGRAM where setting_id=@v_setting_id
    and group_id =
        (select group_id
        from egpl_pref_group
        where group_type = 'departmental'
        and department_id=@v_department_id)

    INSERT INTO EGPL_PROGRAM
    (GROUP_ID, SETTING_ID, SETTING_VAL, IS_PREFERENCE, MODIFIER_ID, MODIFIED_DATE)
    VALUES
    (@v_group_id, @v_setting_id, @v_setting_val,'n',1,getdate());

    PRINT('Inserted the following value for group ' + convert(nvarchar, @v_group_id ))
    PRINT('Setting_id : ' + convert(nvarchar, @v_setting_id) + ' setting_val : ' + @v_setting_val)
END

Upvotes: 3

Views: 15259

Answers (2)

Mike Clancy
Mike Clancy

Reputation: 11

Check the table for columns that do not allow nulls AND also be sure to check your table for triggers if you have modified it. This issue vexed me for most of an afternoon before I realized it was the trigger reporting the error.

Upvotes: 1

paparazzo
paparazzo

Reputation: 45096

Check the table for columns that do not allow nulls

Either the value of one of those columns is null or you are not passing that column at all.
If you have a column that is not null in not in the list of columns then the insert will fail in this manner.

Upvotes: 3

Related Questions