Groups | Blog | Home
all groups > sql server (alternate) > january 2004 >

sql server (alternate) : IF statement in Stored Procedure


cliff NO[at]SPAM walkacrossfire.com
1/27/2004 8:55:55 PM
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
sql NO[at]SPAM hayes.ch
1/28/2004 2:56:03 AM
[quoted text, click to view]

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?

sql NO[at]SPAM hayes.ch
1/28/2004 6:19:09 AM
[quoted text, click to view]

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.

cliff rubin
1/28/2004 11:29:00 AM
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 ***
cliff rubin
1/28/2004 12:39:00 PM

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 ***
AddThis Social Bookmark Button