Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Calculation in stored procedure

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2004-09-17 : 06:14:28
I have a sql table, tblParams, with a field called NextReqNo. Using a stored procedure I want to get the number in NextReqNo, add 1 to it, update the table, and then pass the new value to a text box on an asp.net web page.I want to do this in a stored procedure.

Can anyone help me with this please. Please make it simple - I am a newbie

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-09-17 : 06:33:43
This tblParams, does it only contain 1 row with the last used NextReqNo ?
or
does it contain a list of all the used NextReqNo ?
- In that case an update to the table doesn't make sense, an insert would.

rockmoose
/* Chaos is the nature of things...Order is a lesser state of chaos */
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2004-09-17 : 07:15:18
It just has the last used number in it - 1 row
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-17 : 07:24:39
this should help:

declare @NextReqNo int

update tblParams
set @NextReqNo = NextReqNo + 1,
NextReqNo = @NextReqNo

return @NextReqNo



Go with the flow & have fun! Else fight the flow
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2004-09-17 : 09:21:39
Brilliant - thank you so much

I had to change it slightly (also I simplified the names for my posting)

CREATE PROCEDURE spRMU_GetNextRequestNo

@NextReqNo int OUTPUT

as

update tblCounterTable
set @NextReqNo = NextRequestNo + 1,
NextRequestNo = @NextReqNo

return @NextReqNo
GO
Go to Top of Page
   

- Advertisement -