Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Location
    Pinedale, AZ
    Posts
    1

    Red face Unanswered: Updating duplicate descriptions

    I have just written my first procedure in Microsoft SQL. I have written procedures for Oracle before. I am trying to update a description field. I have a parts list and one part number might have several descriptions. I want to set all the descriptions to the first value encountered in the table for that part number. I think the procedure should work, but my records are never updating. Please take a look and let me know what I am doing wrong.

    Thanks!!

    DECLARE Parts CURSOR
    FOR
    SELECT partnumber, description
    FROM parts2
    ORDER BY partnumber

    OPEN Parts

    FETCH NEXT FROM Parts
    WHILE (@@FETCH_STATUS <> -1)
    BEGIN
    IF (@@FETCH_STATUS <> -2)
    BEGIN
    BEGIN TRANSACTION
    UPDATE Parts2
    SET parts2.description = description
    WHERE parts2.partnumber = partnumber
    and parts2.description <> description
    COMMIT
    END
    FETCH NEXT FROM Parts
    END
    CLOSE Parts
    DEALLOCATE Parts

  2. #2
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393

    Re: Updating duplicate descriptions

    SELECT partnumber, description
    FROM parts2
    ORDER BY partnumber

    UPDATE Parts2
    SET parts2.description = description
    WHERE parts2.partnumber = partnumber
    and parts2.description <> description


    you put Description into Description
    that's why there's no updating



    Can you give some data exemple of your table Parts2

  3. #3
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393

    Re: Updating duplicate descriptions

    you're not using your Parts cursor in your update query
    so you're just putting
    descr into descr

    get your descr value from your Parts cursor

  4. #4
    Join Date
    Nov 2003
    Location
    FRANCE
    Posts
    393

    Re: Updating duplicate descriptions

    declare @partnumber varchar(100), @description varchar(1000)

    ...

    fetch next Parts into @partnumber ,@description


    ...

    UPDATE Parts2
    SET parts2.description = @description
    WHERE parts2.partnumber = @partnumber
    and parts2.description <> description

Posting Permissions

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