473,769 Members | 5,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

resources - stored procedure

I have created the following stored procedure whereby it will check
whether the categoryID is valid and if it is then the updation will be
performed, else a -1 will be returned. This procedure will be execute
with asp. Is this considered to be efficient?.
create procedure usp_updateCateg ories
@CategoryID int
@CategoryDescri ption varchar(30),
@ParentCategory ID int
AS SET NOCOUNT ON

if exists(SELECT top 1* FROM categories WHERE CategoryID=@Cat egoryID)
begin
UPDATE categories set
CategoryDescrip tion=@CategoryD escription,Pare ntCategoryID=@P arentCategor
yID WHERE CategoryID=@Cat egoryID
Select 0
end
else
Select -1

Return
GO
Regards

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #1
5 1722
CJM

"Eugene Anthony" <so***********@ yahoo.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
I have created the following stored procedure whereby it will check
whether the categoryID is valid and if it is then the updation will be
performed, else a -1 will be returned. This procedure will be execute
with asp. Is this considered to be efficient?.
create procedure usp_updateCateg ories
@CategoryID int
@CategoryDescri ption varchar(30),
@ParentCategory ID int
AS SET NOCOUNT ON

if exists(SELECT top 1* FROM categories WHERE CategoryID=@Cat egoryID)
begin
UPDATE categories set
CategoryDescrip tion=@CategoryD escription,Pare ntCategoryID=@P arentCategor
yID WHERE CategoryID=@Cat egoryID
Select 0
end
else
Select -1

Return
GO


Eugene,

This should really be posted in one of the SQL server groups. [Follow-ups
set to m.p.sqlserver.p rogramming]

There is nothing particularly wrong with your implementation; AFAIK it's not
an absolute howler. You may or may not be able to improve on it, on the
other hand, SQL Server will know what you are trying to achieve and will
optimise the query accordingly when it works out the execution plan. The key
is to test this implementation against and others you can think of in Query
Analyzer - see which costs the most.

Chris
Jul 22 '05 #2
CJM wrote:

This should really be posted in one of the SQL server groups.


I disagree. it's relevant here (asp.general), because the way the procedure
is written effects the way the client (asp) will interact with the database.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #3
Eugene Anthony wrote:
I have created the following stored procedure whereby it will check
whether the categoryID is valid and if it is then the updation will be
performed, else a -1 will be returned. This procedure will be execute
with asp. Is this considered to be efficient?.
create procedure usp_updateCateg ories
@CategoryID int
@CategoryDescri ption varchar(30),
@ParentCategory ID int
AS SET NOCOUNT ON

if exists(SELECT top 1* FROM categories WHERE CategoryID=@Cat egoryID)
begin
UPDATE categories set
CategoryDescrip tion=@CategoryD escription,Pare ntCategoryID=@P arentCategor
yID WHERE CategoryID=@Cat egoryID
Fine up to here ...
Select 0
end
else
Select -1


Although some may argue, I would use a Return parameter for this rather than
returning a bulky resultset. It makes no sense to return a cursor just to
pass a single value back to the client. To get an idea how much extra data
is sent across the wire when you do this, use the recordset's Save method
after you execute this procedure to save the recordset to an xml file. Since
the xml file is simply text, you will be able to open it in Notepad and see
all the extra stuff that had to be passed along with your single integer
value. To me, using a parameter (Return or output) makes much more sense.
When a parameter is used, the only data sent back to the client over the
network is the value ... nothing else. When the ADO engine receives the
value, it does not have to construct a recordset object and marshal the data
into the cursor. All it has to do is set the parameter object's value to the
value of the data that was returned from the database. You can't get more
efficient than that.

My criteria are:

Use resultsets (Select statements) to return multiple records - you need a
cursor in this type of situation, so you really have no alternative but to
use a select statement to return a resultset.

Use Return and Output parameters to return single values where you do not
need the functionality of a cursor. This applies to the above procedure.

Of course, using Return and output parameters (see
http://groups-beta.google.com/group/...935bd7c531d82b)
makes it a little more difficult to write the vbscript code in asp ... so I
have written a free code generator to make this task a little easier. You
can get it here:
http://www.thrasherwebdesign.com/ind...asp&c=&a=clear

You will have the source code, so you can customize it if you don't like the
names I used for the variables in te generated code.

Anyways, instead of:

*************** ****
Select 0
end
else
Select -1

Return
*************** *****

I would do this:

*************** *******
RETURN 0
end
else
RETURN -1
*************** *******

In your asp page, use an explicit Command object to execute the procedure so
you can retrieve the result of the Return parameter:

Dim cmd, param, catid, catdesc,parcat, retval

set and validate the catid,... variables, then open your
objConn connection, then:

Set cmd=server.Crea teObject("ADODB .Command")
With cmd
.CommandType=ad cmdstoredproc
.CommandText = "usp_updateCate gories"
set .ActiveConnecti on=objConn
set param = .createparamete r("@RETURN_VALU E", _
adInteger, adParamReturnVa lue, 0)
.parameters.app end param
set param = .createparamete r("@CategoryID" , adInteger, _
adParamInput, 0, catid)
.parameters.app end param
set param = .createparamete r("@CategoryDes cription", _
adVarChar, adParamInput, 30, catdesc)
.parameters.app end param
set param = .createparamete r("@ParentCateg oryID", _
adInteger, adParamInput, 0, parcat)
.parameters.app end param
.execute ,,adexecutenore cords
'read the return value here:
retval = .Parameters("@R ETURN_VALUE").v alue
' or, slichtly more efficiently:
' retval=.Paramet ers(0).value
end with
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #4
Is having different ways of executing the stored procedures from asp
considered to be acceptable in the industry or does it all have to be
the same standard.

Regards

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #5
Eugene Anthony wrote:
Is having different ways of executing the stored procedures from asp
considered to be acceptable in the industry or does it all have to be
the same standard.


There's always been different ways, some better than others. I'm not sure I
follow you.

My practice is to use what I consider to be the best way depending on the
specific situation. Others may have a different practice.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
22146
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
6703
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...
3
2805
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default" when I launched the IBM Distributed Debugger via D:\IBMDebug>idebug.exe -qdaemon -quiport=8000,8001 First, a bit of background. I am running DB2 V7.2 with Fixpack 9 applied on Windows XP Professional (all critical service applied). I've written...
4
3191
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the Throwable as an OUT parameter and what datatype should I use in the CREATE PROCEDURE and DROP PROCEDURE statements? Here's what I tried: - the method signature for the stored procedure included: Throwable throwable
8
7944
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
5459
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
2654
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how to call them from an ASP.Net page Every modern database system has a stored procedure language. SQL Server is no different and has a relatively sophisticated and easy to use system. This article will not attempt to go into depth in explaining...
7
3470
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function 'UpdateRegistrant' expects parameter '@EMail', which was not supplied. The field value was null in the database and not changed in the FormView so is null going back into the stored procedure. I'm stumped and would greatly appreciate any suggestions.
2
4108
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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
10045
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...
0
8872
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...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.