Insert

  • When Iam trying to insert a table I am getting follwin mesg.

    Server: Msg 515, Level 16, State 2, Line 4

    Cannot insert the value NULL into column 'DiffReason', table 'PerfMeasure.dbo.QuarterlyEntry'; column does not allow nulls. INSERT fails.

    The statement has been terminated.

    I understand that I didnt allow NULLS for that column but I have set it to some default value,still i am getting this error.

  • if you do INsert into table (DiffReason) values (NULL), the default won't be used because you supplied a value (even if the value is null).

  • so..u want me to allow NULLS there and it works fine.

  • Indeed,

    Instead of INsert into table (DiffReason) values (NULL)

    try using the Default keyword

    INsert into table (DiffReason) values (Default),

  • No, just don't include the column in the insert if you don't insert it. If this is a general statement, then you have to do something like this :

    Insert into... values (ISNULL(@Varname), @DefaultValue))

  • FYI.. Iam not inserting particular values in it, I am inserting complete table from one DB to another

  • You'll hve to use the isnull technic... that's the simple way around this one.

  • Ok this is query..

     

    INSERT INTO perfmeasure..Quarterlyentry

    (

      ProjectedQtr ,

     Yr_EndProjected ,

     Diff  ,

     DiffPercent ,

     DiffReason ,

     CorrectiveAction

     

     

    &nbsp

    SELECT  

      Projected_Qtr1 ,

     Yr_EndProjected ,

     Diff  ,

     DiffPercent ,

     DiffReason,

     CorrectiveAction 

     

    FROM PM..quarterlyEntry

  • SO???

    Select..

    isnull(Diffe, @Defaultvalue)

    What are you not getting?

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply