473,889 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IF statement in Stored Procedure

Here's my stored procedure:

CREATE PROCEDURE proc
@id varchar(50),@ps wd 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 110320
cl***@walkacros sfire.com (Cliff) wrote in message news:<54******* *************** ****@posting.go ogle.com>...
Here's my stored procedure:

CREATE PROCEDURE proc
@id varchar(50),@ps wd 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***@walkacro ssfire.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
22156
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my application server can talk to the database. I've determined the failure occurs when the the following statement is executed: cstmt.execute(); (due to the failure of println statements placed afterwards). I get the following error after trying to...
0
6711
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
4
8107
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure creates a string of custom SQL statement and returns this string back to the main stored procedure. This SQL statements work fine on there own. The SQL returned from the sub stored procedure are returned fine. The datatype of the variable that...
8
7952
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have created a temporary database with a tables space. Verified that DECLARE GLOBAL TEMPORARY TABLE TEMP (A INTEGER); INSERT INTO SESSION.TEMP VALUES(10); SELECT A FROM SESSION.TEMP; works from a query tool.
2
5470
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
4720
by: nbohana | last post by:
I am trying to code an compile a stored procedure without success. So I generated one using Microsoft Visule C# .Net. and it follows. One of the problems is that it will not compile. Some of the message won't to put ';' all over the place, I some need help!!! These are some of the compile messages. ; expected Cannot use more than one type in a for, using, fixed, or declaration statement = (cannot specify constructor arguments in...
1
13675
by: deepdata | last post by:
Hi, I am trying to fetch data from db2 (express version) database by calling stored procedure. I have tried to use both cursor and for loop but still i am getting error. --======Start procedure============= Create PROCEDURE get_timedout_scripts (
1
7539
by: peaceburn | last post by:
Hi, I'm gonna pull my hair in the coming days with these DB2 stored procedures. So the issue, let's assume a simple stored procedure like this : CREATE PROCEDURE MYSCHEMA.PROCEDURE1 ( ) DYNAMIC RESULT SETS 1 ------------------------------------------------------------------------
2
10600
by: savio XCIX | last post by:
I created the following stored procedure: ======= CREATE PROCEDURE TBLNAME.proc_test (IN p_custnum VARCHAR(8), IN p_zipcode CHAR(5), OUT r_valid CHAR(1), OUT r_bal DECIMAL(9,2)) LANGUAGE SQL BEGIN
4
5085
by: barmatt80 | last post by:
I am stumped on the error reporting with sql server. I was told i need to return @SQLCode(code showing if successful or not) and @ErrMsg(and the message returned). I am clueless on this. I wrote this procedure: ALTER PROCEDURE . @Emp_SSN int, @Annual_Forward decimal(10,2),
0
11187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10784
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6021
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.