• I'll try to explain using your original code.

    USE [OutletRetail]

    GO

    /****** Object: StoredProcedure [Outlet].[sp_UpdateProductStatus] Script Date: 01/16/2014 19:58:47 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER OFF

    GO

    --Updates Product status codes to Available if NULL

    ALTER PROCEDURE [Outlet].[sp_UpdateProductStatus]

    AS

    DECLARE @strProductNo varchar(20)

    --You declare 2 SellerNo.

    --The first one is to fetch from the cursor

    DECLARE @strSellerNo1 varchar(10)

    --and the second one is to check for a different value for SellerNo

    DECLARE @strSellerNo2 varchar(10)

    DECLARE UpdateProductCursor CURSOR FOR

    --This is your cursor definition, if you run this query, you'll know the values that will be used.

    --Be aware that cursors defined with the default options are dynamic and affected by updates to the data.

    SELECT Product_No, Seller_No

    FROM Outlet.tblProductMaster

    WHERE Product_Status IS NULL

    OPEN UpdateProductCursor

    --This retrieves the first values of the cursor.

    --At the end of your while cycle, you'll have the same statement to navigate through the cursor.

    FETCH NEXT FROM UpdateProductCursor INTO @strProduct_No, @strSellerNo1

    WHILE @@FETCH_STATUS = 0

    BEGIN

    SET @strSellerNo2 = NULL

    SELECT @strSellerNo2 = Seller_No

    FROM Outlet.tblProductMaster

    WHERE Product_No = @strProductNo

    --Here, you're looking for rows with the same product_No but different Seller_No

    --If there's more than one value for Seller_No for the same product, the variable will have a value assigned

    --If not, it will stay NULL

    AND Seller_No <> @strSellerNo1

    AND Product_Status = 'Available'

    --This is a validation to run the update only if the product has a single SellerNo.

    IF (@strSellerNo2 IS NULL)

    BEGIN

    UPDATE Outlet.tblProductMaster

    SET Product_Status = 'Available'

    WHERE Product_No = @strProductNo

    AND Seller_No = @strSellerNo1

    END

    I would still recommend that you post the complete details to improve the code and get rid of this cursor.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2