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.
| Author |
Topic |
|
WelshPunk
Yak Posting Veteran
67 Posts |
Posted - 2008-04-18 : 03:46:21
|
| Hi everyoneI am new to sqlserver so please be kindI 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+1I 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 OUTPUTAS....other codeUPDATE YourTableSET @FormCount=dorm_count=form_count+1WHERE PKCol=@IDGO[/code]and execute like thisDECLARE @ReturnVar intEXEC YourProc {your ID value here},@ReturnVar OUTPUTSELECT @ReturnVar AS 'new count value'i assume you pass @ID the pk col value of record whose form count needs to be updated. |
 |
|
|
WelshPunk
Yak Posting Veteran
67 Posts |
Posted - 2008-04-18 : 04:01:21
|
| Thanks for the quick replyI 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 outputASUPDATE form_count SET form_count = form_count +1//neet to somehow set the output param to the new form_cout hereGO |
 |
|
|
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? |
 |
|
|
WelshPunk
Yak Posting Veteran
67 Posts |
Posted - 2008-04-18 : 04:06:45
|
| Yes but in a return parameter |
 |
|
|
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? |
 |
|
|
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 |
 |
|
|
|
|
|