468,321 Members | 1,848 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

IF statement in Stored Procedure

Here's my stored procedure:

CREATE PROCEDURE proc
@id varchar(50),@pswd varchar(20),@no_go int OUTPUT
AS
SET NOCOUNT ON
SELECT user_id FROM table
WHERE user_id=@id AND pswd=@pswd
IF @@ROWCOUNT = 0
BEGIN
SET @no_go = 1
END
ELSE
BEGIN
SELECT date,date_mod FROM ans
WHERE user_id=@id
SET @no_go = 0
END

This statement outputs the second recordset (SELECT FROM ans) whether
@@ROWCOUNT is 0 or not. Why is that and how do I stop it
Jul 20 '05 #1
4 110077
cl***@walkacrossfire.com (Cliff) wrote in message news:<54**************************@posting.google. com>...
Here's my stored procedure:

CREATE PROCEDURE proc
@id varchar(50),@pswd varchar(20),@no_go int OUTPUT
AS
SET NOCOUNT ON
SELECT user_id FROM table
WHERE user_id=@id AND pswd=@pswd
IF @@ROWCOUNT = 0
BEGIN
SET @no_go = 1
END
ELSE
BEGIN
SELECT date,date_mod FROM ans
WHERE user_id=@id
SET @no_go = 0
END

This statement outputs the second recordset (SELECT FROM ans) whether
@@ROWCOUNT is 0 or not. Why is that and how do I stop it


There's nothing obviously wrong there (or at least when I quickly
tried a similar proc it worked for me) - have you used the debugger to
verify that @@ROWCOUNT really is 0 at that point? And have you removed
anything from your sample code that comes between the first SELECT and
the IF statement?

Simon
Jul 20 '05 #2
the procedure works fine in query analyzer, but in PERL, using DBI, it
returns records past the if statemment, even if not true. Doen't a
stored procedure die, if the conditions aren't met?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

also, since PERL can pull in the data past an if statement, isn't that a
security problem? The stored procedure has got to die
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
cliff rubin <cl***@walkacrossfire.com> wrote in message news:<40***********************@news.frii.net>...
the procedure works fine in query analyzer, but in PERL, using DBI, it
returns records past the if statemment, even if not true. Doen't a
stored procedure die, if the conditions aren't met?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


If the procedure works in QA, then there's no good reason for it to
return different results when called from a different client. Unless
somehow the DBI interface is doing something strange to the input, so
that what is passed in from DBI is not the same as what is passed in
from QA, but that's an entirely uninformed guess. I suspect you will
get a better answer in a Perl or DBI forum.

Simon
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Thomasb | last post: by
2 posts views Thread by Dino L. | last post: by
2 posts views Thread by nbohana | last post: by
1 post views Thread by peaceburn | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.