UPDATE makes cells NULL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • enginoren
    New Member
    • Feb 2010
    • 6

    UPDATE makes cells NULL

    Hi,

    I'm trying to update a coloumn in table A with the corresponding values in table B. It updates the values correctly for the rows that meet the criteria, but changes the values of other rows to NULL.

    update ALTMALZEME
    set PROJEKODU = (select YENIPROJE from SevkiyatTMP WHERE SevkiyatTMP.MAL ZEMENO = ALTMALZEME.ALTM PKOD)

    the Select command works fine and selects the needed rows, but the remaining rows get the value NULL in the coloumn PROJEKODU.

    How can i exclude the remaining rows?

    Thanks
  • enginoren
    New Member
    • Feb 2010
    • 6

    #2
    update ALTMALZEME
    set PROJEKODU = SevkiyatTMP.YEN IPROJE
    FROM dbo.ALTMALZEME INNER JOIN dbo.SevkiyatTMP
    ON dbo.ALTMALZEME. ALTMPKOD = dbo.SevkiyatTMP .MALZEMENO

    This solved my problem :)

    Comment

    • OraMaster
      New Member
      • Aug 2009
      • 135

      #3
      Hello

      Slight modification in your update query

      update ALTMALZEME
      set PROJEKODU = SevkiyatTMP.YEN IPROJE
      FROM dbo.ALTMALZEME INNER JOIN dbo.SevkiyatTMP
      ON dbo.ALTMALZEME. ALTMPKOD = dbo.SevkiyatTMP .MALZEMENO
      WHERE PROJEKODU <> SevkiyatTMP.YEN IPROJE

      Since I think there is no point in updating the column value with same value.

      Comment

      • enginoren
        New Member
        • Feb 2010
        • 6

        #4
        Thanx for the advice OraMaster, you are right about the point but there will not be such possibility. The new value will always be different. But thanx for reminding, will be handy somewhere else ;)

        thanx
        Engin

        Comment

        Working...