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
 General SQL Server Forums
 New to SQL Server Programming
 Update Query Help

Author  Topic 

WelshPunk
Yak Posting Veteran

67 Posts

Posted - 2008-04-18 : 03:46:21
Hi everyone

I am new to sqlserver so please be kind

I am trying to use output parameters for the first time. I have a table that has one field which I call form_count of data type int. I update the table and make form_count = form_count+1

I then need to assign the new form_count to an output parameter to return. Could anyone please give an example

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-18 : 03:51:41
[code]CREATE PROC YourProc
@ID int
@FormCount int=0 OUTPUT
AS
....other code

UPDATE YourTable
SET @FormCount=dorm_count=form_count+1
WHERE PKCol=@ID
GO
[/code]
and execute like this

DECLARE @ReturnVar int

EXEC YourProc {your ID value here},@ReturnVar OUTPUT

SELECT @ReturnVar AS 'new count value'

i assume you pass @ID the pk col value of record whose form count needs to be updated.
Go to Top of Page

WelshPunk
Yak Posting Veteran

67 Posts

Posted - 2008-04-18 : 04:01:21
Thanks for the quick reply

I am not passing anything into the procedure it is a quick and dirty update so that I can use the formcount in another procedure (in dot net)

CREATE PROCEDURE [DBO].[get_form_count] @return int output
AS
UPDATE form_count
SET form_count = form_count +1
//neet to somehow set the output param to the new form_cout here


GO
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-18 : 04:05:32
and you want to get the new count value after updation of each record?
Go to Top of Page

WelshPunk
Yak Posting Veteran

67 Posts

Posted - 2008-04-18 : 04:06:45
Yes but in a return parameter
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-18 : 04:34:58
Can i ask waht your full requirement is? where will you be using this values?
Go to Top of Page

WelshPunk
Yak Posting Veteran

67 Posts

Posted - 2008-04-18 : 05:09:09
I have a table that holds text descriptions and a series of fields that are used to generate a form in a survey. When the user updates the form I update a table called obs_data with the items that the user selected. In order to retrieve the data and display the form at a later date I need to insert a form_count into the table. So before I insert the data into the obs_data table I need to get a new form_count value.

So in my web form code behind page just before I insert every survey row I need to first get a form_count so that every row of data in the survey in this particular form will have the same form_count. if the user needs to return to the survey I can get all the data by form_count
Go to Top of Page
   

- Advertisement -