Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Location
    South Africa
    Posts
    1

    Unanswered: Store Procedure to Increment Fields

    I am new to Stored procedures so I will write this query in PSEUDO Code. I need to update two counters in a Database like this.

    Update ThisTable WHERE ID =@pkID
    Set ThisTable.Hits = ThisTable.Hits + 1
    Set ThatTable.Hits = ThatTable.Hits + 1
    WHERE ThatTable.ID = ThisTable.Category

    Basically I am trying to update a Hit Counter by ONE in the FIRST Table and then update the Hit Counter in another Table that is related to the FIRST Table.

    I need STORED PROCEDURE to this so can any of Guris out there help.

    Thanks in advance.

  2. #2
    Join Date
    Oct 2003
    Location
    Dallas
    Posts
    76

    ....

    this should get you started with the ideal

    declare @cnt as int, @cnt1 as int
    set @cnt = (select counter from table)
    set @cnt1 = @cnt+1

    Update x
    Set x.Hits = @cnt1
    From ThisTable x
    WHERE x.ID = @pkID --I assume this is the ID that you are passing in

    Update x
    Set x.Hits = @cnt1
    From ThatTable x
    WHERE x.ID = @pkID --I assume this is the ID that you are passing in

Posting Permissions

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