Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2002
    Posts
    46

    Unanswered: a Null check for a single record

    Hi,
    I have a table that may contains Null filled columns.
    I have a SP that do Update and insert.
    How can i do a null check to avoid trying to update null fields?
    let say Type_1 column is null, I need a condition that will do a quick check (single record is sufficient) to see that it has null value and to skip the update command:

    CREATE PROCEDURE Lan_Insert_Data_Type
    as
    DECLARE @Single_Rec int
    Begin

    -- ????? HERE comes the condition ----

    UPDATE Data_type
    SET Product_Num = LanTable.ProductNum,
    Data =LanTable.Type_1
    FROM Data_Type p
    JOIN LanTable
    ON Lantable.ProductNum = p.Product_num where p.Data_Type =1

    Thanks

    Yossi

  2. #2
    Join Date
    Jul 2002
    Posts
    63
    --Try This

    CASE When Type_1 IS NULL
    Then
    --Do nothing
    SET @Single_Rec = @Single_Rec

    ELSE

    UPDATE Data_type
    SET Product_Num = LanTable.ProductNum,
    Data =LanTable.Type_1
    FROM Data_Type p
    JOIN LanTable
    ON Lantable.ProductNum = p.Product_num where p.Data_Type =1

    END

  3. #3
    Join Date
    Aug 2002
    Posts
    46
    Originally posted by eschapir
    --Try This

    CASE When Type_1 IS NULL
    Then
    --Do nothing
    SET @Single_Rec = @Single_Rec

    ELSE

    UPDATE Data_type
    SET Product_Num = LanTable.ProductNum,
    Data =LanTable.Type_1
    FROM Data_Type p
    JOIN LanTable
    ON Lantable.ProductNum = p.Product_num where p.Data_Type =1

    END
    Thaks for the reply
    but its not working,
    maybe i missed some thing

  4. #4
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249
    /* something like this ? */

    if not exists(
    select *
    FROM Data_Type p
    JOIN LanTable
    ON Lantable.ProductNum = p.Product_num
    where p.Data_Type=1 and LanTable.Type_1 is null
    )
    UPDATE Data_type
    SET Product_Num = LanTable.ProductNum,
    Data =LanTable.Type_1
    FROM Data_Type p
    JOIN LanTable
    ON Lantable.ProductNum = p.Product_num where p.Data_Type =1

  5. #5
    Join Date
    Aug 2002
    Posts
    46
    Originally posted by ispaleny
    /* something like this ? */

    if not exists(
    select *
    FROM Data_Type p
    JOIN LanTable
    ON Lantable.ProductNum = p.Product_num
    where p.Data_Type=1 and LanTable.Type_1 is null
    )
    UPDATE Data_type
    SET Product_Num = LanTable.ProductNum,
    Data =LanTable.Type_1
    FROM Data_Type p
    JOIN LanTable
    ON Lantable.ProductNum = p.Product_num where p.Data_Type =1
    Works great...
    Thanks mate

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •