If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Store Procedure to Increment Fields

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-14-03, 18:03
FailSafe FailSafe is offline
Registered User
 
Join Date: Sep 2003
Location: South Africa
Posts: 1
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.
Reply With Quote
  #2 (permalink)  
Old 10-30-03, 15:26
mkkmg mkkmg is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On