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
 Transact-SQL (2000)
 Not hitting part of sql??

Author  Topic 

gotafly
Yak Posting Veteran

54 Posts

Posted - 2006-01-27 : 14:08:23
CREATE PROCEDURE dbo.updateVotes
(
@StringVal nvarchar (50),
@StringVal1 nvarchar (50),
@DelimiterVal nvarchar (10),
@NameVal nvarchar (50),
@lNameVal nvarchar (50),
@genderVal integer,
@ageVal integer,
@EmailVal nvarchar (50),
@zipVal nvarchar (50),
@hearVal integer
)
as
begin
declare @NextString nvarchar(50)
declare @NextString1 nvarchar(50)
declare @Pos integer
declare @Pos1 integer
declare @NextPos integer
declare @NextPos1 integer
declare @CountItems integer

--Initialize
set @NextString = ''
set @StringVal = @StringVal + @DelimiterVal
set @StringVal1 = @StringVal1 + @DelimiterVal

--Get position of first Comma
set @Pos = charindex(@DelimiterVal,@StringVal)
set @Pos1 = charindex(@DelimiterVal,@StringVal1)
set @NextPos = 1
set @NextPos1 = 1

--Loop while there is still a comma in the String of levels
while (@pos <> 0)
begin
set @NextString = substring(@StringVal,1,@Pos - 1)
set @NextString1 = substring(@StringVal1,1,@Pos1 - 1)

UPDATE vote WITH (ROWLOCK) SET no_votes = no_votes + 1 WHERE (answer = ltrim( rtrim(@NextString1))) AND (poll_id = CAST(@NextString as INTEGER)
)

set @StringVal = substring(@StringVal,@pos +1,len(@StringVal))
set @StringVal1 = substring(@StringVal1,@pos1 +1,len(@StringVal1))

set @NextPos = @Pos
set @pos = charindex(@DelimiterVal,@StringVal)

set @NextPos1 = @Pos1
set @pos1 = charindex(@DelimiterVal,@StringVal1)
end

return

************ Does not run the code below????

SELECT @CountItems = COUNT(*)
FROM dbo.voter
WHERE voteremail = @EmailVal
IF @CountItems= 0
BEGIN
INSERT INTO dbo.voter
(votername, lNameVal, voteremail, genderVal, ageVal, zipVal, hearVal)
VALUES (@NameVal,@lNameVal, @EmailVal, @genderVal, @ageVal, @zipVal, @hearVal)
END
end
GO

jhermiz

3564 Posts

Posted - 2006-01-27 : 14:29:20
I shouldn't answer this because you have not provided any text or question, you simply pasted your code and expect us to go through all of it. Pretty sickning!

You have a return statement so that stops the processing it will never hit that last SELECT.

Jon



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

gotafly
Yak Posting Veteran

54 Posts

Posted - 2006-01-27 : 14:33:39
Well I did have...

************ Does not run the code below????
Don't I need the return with the while loop

Dave



quote:
Originally posted by jhermiz

I shouldn't answer this because you have not provided any text or question, you simply pasted your code and expect us to go through all of it. Pretty sickning!

You have a return statement so that stops the processing it will never hit that last SELECT.

Jon



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]

Go to Top of Page

jhermiz

3564 Posts

Posted - 2006-01-27 : 14:54:11
quote:
Originally posted by gotafly

Well I did have...

************ Does not run the code below????
Don't I need the return with the while loop

Dave



quote:
Originally posted by jhermiz

I shouldn't answer this because you have not provided any text or question, you simply pasted your code and expect us to go through all of it. Pretty sickning!

You have a return statement so that stops the processing it will never hit that last SELECT.

Jon



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]





No the end ends a while loop, the return just does that it returns. Rather than asking me why dont you try it and test it ?
Get rid of the result or at least put it at the end of your sproc.



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page
   

- Advertisement -