stored procedure issues

having problems with this stored proc.


I can get it to populate the fields that it needs to but its not auto incrementing the table as designed.

Basically it's supposed to go like this

Select the top record with the lowest int in IRBTurnCounter then it needs to add a 1 to the value of the selected record so instead of IRBTurnCounter for the selected record being 1 it becomes a 2


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[P_sp_EmailerProgramV2]
	-- Add the parameters for the stored procedure here

AS
DECLARE @Email nvarchar(50),
@IRBTurnCounter int,
@FirstName nvarchar(50)

	/* SET NOCOUNT ON */
select top 1 Email, IRBTurnCounter, FirstName from tbl_IRBMembors Order by  IRBTurnCounter Asc

UPDATE tbl_IRBMembors
SET 
IRBTurnCounter = @IRBTurnCounter + 1,
Email = @Email
WHERE Email = @Email

Open in new window

HawaiiDragonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
try

select top 1 Email, IRBTurnCounter, FirstName from tbl_IRBMembors Order by  IRBTurnCounter Asc
-->
select top 1 @IRBTurnCounter = IRBTurnCounter + 1 from tbl_IRBMembors Order by  IRBTurnCounter Asc
0
HawaiiDragonAuthor Commented:
Nope no records added
0
HainKurtSr. System AnalystCommented:
there is no insert statement in your code, only update...
sure it wont insert any new record...

try this code below...


...
/* SET NOCOUNT ON */
select top 1 @Email = Email, @IRBTurnCounter = IRBTurnCounter + 1 from tbl_IRBMembors Order by IRBTurnCounter Asc

UPDATE tbl_IRBMembors
SET 
IRBTurnCounter = @IRBTurnCounter,
Email = @Email
WHERE Email = @Email

Open in new window

0
HainKurtSr. System AnalystCommented:
but I don't understand what you are trying to do here...

for example why you get Email? why do you update it?

the code below increments the max number to max + 1

please give example of what you are trying to do... code does not make any sense to me...
ALTER PROCEDURE [dbo].[P_sp_EmailerProgramV2]
	-- Add the parameters for the stored procedure here
AS
@IRBTurnCounter int

/* SET NOCOUNT ON */
select @IRBTurnCounter = max(IRBTurnCounter) tbl_IRBMembors

UPDATE tbl_IRBMembors
   SET IRBTurnCounter = @IRBTurnCounter +1,
 WHERE IRBTurnCounter = @IRBTurnCounter

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HawaiiDragonAuthor Commented:
Sorry HainKurt,  I forgot to assing points!

Explanation:

When a new document is assigned to a user (admin of department) the filed is changed by 1 so that they have to wait in line to get the next document. Its a strage process but when all student documents are simmliar its so that their turns in grading the documents is fair.

Matt
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.