Documente Academic
Documente Profesional
Documente Cultură
(http://domain.com/PlanetSourceCode/default.asp)
SQL Stats:
(http://domain.com/URLSEO/entrancegeneric/ShowWorldSeOnly!asp/lngWId!5/anyname.htm) (http://domain.com/URLSEO/vb/discussion/AskAProMain!asp/blnURLSEO!true/lngWId
Code/Articles (#)
Newest (http://domain.com/vb/scripts/BrowseCategoryOrSearchResults.asp?grpCategories=-1&optSort=DateDescending&
txtMaxNumberOfEntriesPerPage=10&blnNewestCode=TRUE&blnResetAllVariables=TRUE&lngWId=5)
Browse categories (http://domain.com/vb/scripts/BrowseAllCategories.asp?lngWId=5)
Search (http://domain.com/vb/scripts/search.asp?lngWId=5)
----------------------- (#)
Upload code / articles (http://domain.com/vb/authors/determine_author_type.asp?lngWId=5)
Open letter from moderators (http://domain.com/vb/misc/OpenLetterFromPSCModerators.asp?lngWId=5)
----------------------- (#)
Articles & tutorials (http://domain.com/vb/Tutorial/default.asp?lngWId=5)
Recommended reading (http://domain.com/vb/Bookstore/default.asp?lngWId=5)
Top Code (#)
Coding contest (http://domain.com/vb/contest/ContestInfo.asp?lngWId=5)
Coding contest leader board (http://domain.com/vb/contest/ContestAndLeaderBoard.asp?lngWId=5)
Coding contest 'All-Time Hall of Fame' (http://domain.com/vb/scripts/BrowseCategoryOrSearchResults.asp?grpCategories=-1&
txtMaxNumberOfEntriesPerPage=10&blnTopCode=True&blnResetAllVariables=TRUE&lngWId=5)
----------------------- (#)
Code of the day newsletter (http://domain.com/vb/CodeOfTheDay/signup.asp?lngWId=5)
Community (#)
Ask a pro discussion forum (http://domain.com/vb/discussion/default.asp?lngWId=5)
Games (http://www.vWorker.com/RentACoder/DotNet/misc/Games.aspx?lngWId=5)
Code of the day newsletter (http://domain.com/vb/CodeOfTheDay/signup.asp?lngWId=5)
Jobs (#)
Search for a job (http://domain.com/vb/jobs/SearchJobs.asp?lngWId=5)
Post a job (http://domain.com/vb/jobs/PostJob.asp?lngWId=5)
Other (#)
My profile (http://domain.com/vb/authentication/MyPlanetSourceCode/CustomizeInfo.asp?lngWId=5)
How to link to us (http://domain.com/vb/LinkToUs/default.asp?lngWId=5)
Awards/Reviews/Raves! (http://domain.com/vb/about/Awards.asp?lngWId=5)
Advertising/Media kit (http://domain.com/vb/advertisement/scripts/rates.asp?lngWId=5)
Feedback (http://domain.com/vb/feedback/feedback.asp?lngWId=5)
About the site (http://domain.com/vb/about/AboutTheSiteAndAuthor.asp?lngWId=5)
Goto… (#)
SQL home (http://domain.com/vb/default.asp?lngWId=5)
Site home (http://domain.com/PlanetSourceCode/default.asp?lngWId=-1)
Other sites (http://domain.com/vb/scripts/OtherLinks.asp?lngWId=5)
A big thank you to Mr. Clinton Williams who made an incredibly generous donation to Planet Source Code's T1 fund. On behalf of myself and all the users of Planet Source Code, thank you Mr. Williams for helpi
1 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
(http://domain.com/vb/scripts/EmailToFriend.asp?lngWId=5&txtCodeId=127&txtCodeName=Writing%2520a%2520Stored%2520Procedure& Email
Procedure txtCodeDescription=This%2520article%2520is%2520geared%2520for%2520beginners%2520wanting%2520to%2520learn%2520stored%2520procedures txtCodeDescripti
%2E%2520No%2520prior%2520experience%2520on%2520stored%2520procedures%2520is%2520required %2E%2520No%
%2C%2520however%2520a%2520basic%2520understanding%2520of%2520SQL%2520Query%2520Language%2520might%2520be%2520needed%2E) %2C%2520howe
Submitted on: 7/21/2000 1:12:46 PM
By: Nathan Pond (http://domain.com/vb/authors/ShowBio.asp?lngAuthorId=332084962&lngWId=5)
Level: Beginner
User Rating: By 124 Users
Compatibility:SQL Server 7.0
This article is geared for beginners wanting to learn stored procedures. No prior experience on stored procedures is required, however a basic understanding of SQL Query Language might be needed.
Terms of Agreement:
By using this article, you agree to the following terms...
1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3. You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
ENTER>
2 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
sp_myStoredProcedure
Where column1 = 0
sp_myStoredProcedure 0
3 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
.....
Go
>%
dim dataConn, sSql, rs
set dataConn = Server.CreateObject("ADODB.Conn
dataConn.Open "DSN=webData;uid=user;pwd=passwo
sSql = "Select column1, column2 From Table1"
Set rs = dataConn.Execute(sSql) 'execute sql c
%>
>%
dim dataConn, sSql, rs
set dataConn = Server.CreateObject("ADODB.Conn
dataConn.Open "DSN=webData;uid=user;pwd=passwo
sSql = "sp_myStoredProcedure"
Set rs = dataConn.Execute(sSql) 'execute sql c
%>
>%
dim dataConn, sSql, rs, myInt
myInt = 1 'set myInt to the number we want to
set dataConn = Server.CreateObject("ADODB.Conn
dataConn.Open "DSN=webData;uid=user;pwd=passwo
sSql = "sp_myStoredProcedure " & myInt
Set rs = dataConn.Execute(sSql) 'execute sql c
%>
4 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
>%
dim dataConn, sSql
dim FirstName, LastName
FirstName = "Nathan"
LastName = "Pond"
set dataConn = Server.CreateObject("ADODB.Connection")
dataConn.Open "DSN=webData;uid=user;pwd=password" 'mak
sSql = "sp_myInsert '" & FirstName & "', '" & LastName
dataConn.Execute(sSql) 'execute sql call
%>
>%
dim dataConn, sSql, rs
set dataConn = Server.CreateObject("ADODB.Connection")
dataConn.Open "DSN=webData;uid=user;pwd=password" 'mak
sSql = "Select * From User_Table Where UserName = '" &
Request.Form("UserName") & "' And Password = '
Request.Form("Password") & "'"
Set rs = dataConn.Execute(sSql) 'execute sql call
If rs.EOF Then
'Redirect user, incorrect login
Response.Redirect "Incorrect.htm"
End If
'process logon code
.............
%>
5 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
>%
<--#INCLUDE VIRTUAL="/include/adovbs.inc"-->
dim dataConn, adocmd, IsValid
set dataConn = Server.CreateObject("ADODB.Connection")
dataConn.Open "DSN=webData;uid=user;pwd=password" 'mak
Set adocmd = Server.CreateObject("ADODB.Command")
adocmd.CommandText = "sp_IsValidLogon"
adocmd.ActiveConnection = dataConn
adocmd.CommandType = adCmdStoredProc
adocmd.Parameters.Append adocmd.CreateParameter("retur
adInteger, adParamReturnValue, 4)
adocmd.Parameters.Append adocmd.CreateParameter("usern
adVarChar, adParamInput, 16, _
Request.Form("UserName"))
adocmd.Parameters.Append adocmd.CreateParameter("passw
adVarChar, adParamInput, 16, _
Request.Form("Password"))
adocmd.Execute
IsValid = adocmd.Parameters("return").Value
If IsValid = 0 Then
'Redirect user, incorrect login
Response.Redirect "Incorrect.htm"
End If
'process logon code
.............
%>
Now lets slow down for a minute and I'll go through wha
a command object for ADO. I did this with:
adocmd.CommandText = "sp_IsValidLogon"
6 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
>%
.....
Set adocmd = Server.CreateObject("ADODB.Command")
adocmd.CommandText = "sp_IsValidLogon"
adocmd.ActiveConnection = dataConn
adocmd.CommandType = adCmdStoredProc
adocmd.Parameters.Append adocmd.CreateParameter("usern
adVarChar, adParamInput, 16, Request.Form("UserName"))
adocmd.Parameters.Append .CreateParameter("password",
adVarChar, adParamInput, 16, Request.Form("Password"))
adocmd.Parameters.Append .CreateParameter("return", _
adInteger, adParamReturnValue, 4)
adocmd.Execute
IsValid = adocmd.Parameters("return").Value
.....
%>
I'm not exactly sure why this happens, but I just made
value first, then the parameters.
7 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
if (@myvar=1)
return(1)
else
return(2)
if (@myvar=1)
begin
do this.....
and this.....
return(1)
end
else
begin
do this....
return(2)
end
8 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
Happy Programing!
Your Vote!
Regards,
Nathan
(If this comment was disrespectful, please report it (#) .)
7/29/2000 1:52:13 PM : Brian Lockwood (http://domain.c om/vb/feedbac k/EmailUser.asp?lngWId=5&lngToPersonId=552808284&txtReferralPage=http%3A%2F%2Fw ww%2Eplanet%2Dsource%2Dcode%2Ec om%2Fvb%2Fscripts%2FShow Code%2Easp%3FtxtCodeId%
Excellent article this is the "RIGHT" way to do data access. For a tool that can write stored procedures automatically and uses ADO command objects in VB or ASP to call them using this same syntax see www.lockwoodtech.com. There are products for SQL Se
UUID="00000200-0000-0010-8000-00AA006D2EA4" NAME="ADO Type Library"-->"
(If this comment was disrespectful, please report it (#) .)
9 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
This is because SQL server uses sp for built in stored procedures. When you call a stored procedure that starts with sp, SQL server will look for the built in procedure first, slowing your procedure calls down.
(If this comment was disrespectful, please report it (#) .)
SQL server uses sp as a prefix for its built in stored procedures. If you prefix your stored procedures with sp, SQL server will check for a built in stored procedure first, slighly affecting performance. Its a small amount but as we can choose whatever we want to prefix our spr
do u have any help writing stored procedure to typically create a flat file from the database in comma seperated format..
thanks
palani60173@lycos.com
1/14/2002 12:36:07 AM : Greg Beard (http://domain.com/vb/feedback/EmailUser.asp?lngWId=5&lngToPersonId=3315929912&txtReferralPage=http%3A%2F%2Fww w%2Eplanet%2Dsourc e%2Dc ode%2Ec om%2Fvb%2Fscripts%2FShow Code%2Easp%3FtxtCodeId
Excellent - thanks.
(If this comment was disrespectful, please report it (#) .)
2/7/2002 11:19:03 PM: Derreck (http://domain.com/vb/feedback/EmailUser.asp?lngWId=5&lngToPersonId=3317087362&txtReferralPage=http%3A%2F%2Fww w%2Eplanet%2Dsourc e%2Dc ode%2Ec om%2Fvb%2Fscripts%2FShow Code%2Easp%3FtxtCodeId
YOU ARE DA MAN!!! Finally, i can automate tasks in my shopping cart programs, and reduce overhead. You are a life saver!
(If this comment was disrespectful, please report it (#) .)
10 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
It is strongly recommended that you do not create any stored procedures using sp_ as a prefix. SQL Server always looks for stored procedures beginning with sp_ in this order:
Sir, I need some explanation on Sql Server 7. How u can link a SQL Server 7 to different platform such as Linux, Sun Solaris.Need help urgently.Pls give some idea . sumipraveen@hotmail.com
(If this comment was disrespectful, please report it (#) .)
great article!
by the way, i think sp_ stands for system procedure and not stored procedure.
(If this comment was disrespectful, please report it (#) .)
2/12/2003 9:27:56 AM : Felipe Lima A. Menezes (http://domain.c om/vb/feedbac k/EmailUser.asp?lngWId=5&lngToPersonId=229571071&txtReferralPage=http%3A%2F%2Fw ww%2Eplanet%2Dsource%2Dcode%2Ec om%2Fvb%2Fscripts%2FShow Code%2Easp%3Ftx
Great article!
(If this comment was disrespectful, please report it (#) .)
Thanks for your article. Using plain common sense explanations helped me to know
(If this comment was disrespectful, please report it (#) .)
Thanks again,
(If this comment was disrespectful, please report it (#) .)
where can I find the exact same (wonderful) explanation of stored procedures but for calling them from VB 6.0 (not .asp)?
Hi, The article was very good and everything will work perfectly for SQL Server, however Oracle is another ugly beast that does not work quite as cleanly as SQL Server and requires things such as cursors and packages to return multiple resultsets. Good job though covering
(If this comment was disrespectful, please report it (#) .)
It was a really helpful article for me to understand how to use stored procedures. Thank you so much for being kind enough to write this article in a manner others can easily understand. I think you have been 100% successful on this article. Again thank you very much and wis
(If this comment was disrespectful, please report it (#) .)
11 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
Thanks to you Nathan for helping me out on working with Stored Procedures. I am a beginner on SQL Server2000 and I dont have knowledge on Stored Procs. Your article helps me understand and get me started to work with SP's. Thanks again.
(If this comment was disrespectful, please report it (#) .)
It really helped me in understanding the basic steps of writing stored procedures..Thanks for giving such valuable notes!!
(If this comment was disrespectful, please report it (#) .)
Great.It really helped me in understanding the basic steps of writing stored procedures..Thanks for giving such valuable notes.can i use it with delphi since want to hide password from unauthorized users and have user-login table and user-login form , if so would u give me idea
(If this comment was disrespectful, please report it (#) .)
thanks much , now i m clear about stored preocdure. i have database project ms-sql server with delphi 7 , i have user-login table with field username and userpassword , and have userloginForm , so to hide password from unathorized users . so how to manage it , any help
(If this comment was disrespectful, please report it (#) .)
5/8/2007 10:18:45 PM : Rahat651 (http://domain.c om/vb/feedbac k/EmailUser.asp?lngWId=5&lngToPersonId=77443434146&txtReferralPage=http%3A%2F%2Fww w%2Eplanet%2Dsourc e%2Dc ode%2Ecom%2Fvb%2Fsc ripts%2FShowCode%2Easp%3FtxtCodeI
Good work. But did not write on relation between multiple stored procedures.
(If this comment was disrespectful, please report it (#) .)
IMBC SDN.BHD from Malaysia willing to invest in small and medium sized company/business (any type of business).
Contact:
Mr.Vasan,
General Manager,
IMBC.SDN.BHD
Ph: 0060146301333.
or
E-Mail to: detect@idmservices.net
12 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For fe e dback not re late d to this particular article , ple ase click he re (http://domain.com/vb/fee dback/fe edback.asp?lngWId=5&intTypeOfInquiry=3) .
Search Term…
(http://www.pscode.com/ads/ad_router.asp?lngWId=5&txtURL=&txtFromUrl=%2Fads%2FShowAd%2EAsp&lngWMId=1548&lngAVDRId=833261)
Login (http://domain.com/vb/authentication/Login.asp?txtReturnURL=%2Fvb%2Fscripts%2FShowCode%2Easp%3FtxtCodeId%3D127%26lngWId%3D5)
13 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
(javascript:ShowPopupWindowXYWithScrollbar
/misc/NewUpdateIconExplanation.asp',200,300)
By DuaneÂ
0;Warsham on 6/10
Click here to put this ticker
on your site! (http://domain.com/vb/LinkToUs/default.asp?lngWId=5#NewCodeTicker)
(javascript:ShowPopupWindowXYWithScrollbar
Add to/misc/NewUpdateIconExplanation.asp',200,300)
Active Desktop (http://domain.com/vb/LinkToUs/default.asp?lngWId=5#NewCodeTicker)
SQL
Add this JOINto
ticker EXAMPLE
your desktop! (http://domain.com/vb/LinkToUs/default.asp?lngWId=5#NewCodeTicker)
(http://domain.com
/vb/scripts
Daily/ShowCode.asp?txtCodeId=1378&
Code Email
lngWId=5)
This Site on CD
(javascript:ShowPopupWindowXYWithScrollbar
/misc/NewUpdateIconExplanation.asp',200,300)
Over 7,000 submissions on a super fast CD (http://www.exhedra.com/exhedra/PlanetSourceCode/CD.aspx) !
SQL[RND]
(http://domain.com
/vb/scripts (http://domain.com
/vb/CD
/ShowCode.asp?txtCodeId=1377&
lngWId=5) /PscCd.asp?lngWId=5)
By NEERAJ
KUMAR
Get Paid SHARMA
To Code
on 5/18
(javascript:ShowPopupWindowXYWithScrollbar
/misc/NewUpdateIconExplanation.asp',200,300)
(http://www.vWorker.comNow taking registrations on Rent a Coder (http://www.vWorker.c om/RentACoder/DotNet/SoftwareCoders/HowItWorks.aspx) !
/RentACoder/DotNet
SQL Function For
/SoftwareCoders
Getting The Last Day of
/HowItWorks.aspx)
the Month
(http://domain.com
/vb/scripts
Open letter from moderators (http://domain.com/vb/misc/OpenLetterFromPSCModerators.asp?lngWId=5)
/ShowCode.asp?txtCodeId=1376&
About the site (http://domain.com/vb/about/AboutTheSiteAndAuthor.asp?lngWId=5)
lngWId=5)
Feedback (http://domain.com/vb/feedback/feedback.asp?lngWId=5)
Link to thePatel
By Shirish Site (http://domain.com/vb/LinkToUs/default.asp?lngWId=5)
on
Awards
3/19 (http://domain.com/vb/about/Awards.asp?lngWId=5)
Advertising (http://domain.com/vb/advertisement/scripts/rates.asp?lngWId=5)
Privacy (http://domain.com/vb/scripts/privacy.asp?lngWId=5)
(javascript:ShowPopupWindowXYWithScrollbar
/misc/NewUpdateIconExplanation.asp',200,300)
By Dinesh Kumar S
on 3/3
(javascript:ShowPopupWindowXYWithScrollbar
/misc/NewUpdateIconExplanation.asp',200,300)
14 of 15 6/13/2011 10:10 AM
Writing a Stored Procedure by Nathan Pond http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeI...
(http://www.vWorker.com/RentACoder/DotNet/SoftwareCoders/HowItWorks.aspx)
Code/Articles
Newest (http://domain.com/vb/scripts/BrowseCategoryOrSearchResults.asp?grpCategories=-1&optSort=DateDescending&txtMaxNumberOfEntriesPerPage=10&
blnNewestCode=TRUE&blnResetAllVariables=TRUE&lngWId=5)
Browse categories (http://domain.com/vb/scripts/BrowseAllCategories.asp?lngWId=5)
Search (http://domain.com/vb/scripts/search.asp?lngWId=5)
Upload code / articles (http://domain.com/vb/authors/determine_author_type.asp?lngWId=5)
Open letter from moderators (http://domain.com/vb/misc/OpenLetterFromPSCModerators.asp?lngWId=5)
Articles & tutorials (http://domain.com/vb/Tutorial/default.asp?lngWId=5)
Recommended reading (http://domain.com/vb/Bookstore/default.asp?lngWId=5)
Top Code
Community
Jobs
Other
My profile (http://domain.com/vb/authentication/MyPlanetSourceCode/CustomizeInfo.asp?lngWId=5)
How to link to us (http://domain.com/vb/LinkToUs/default.asp?lngWId=5)
Awards/Reviews/Raves! (http://domain.com/vb/about/Awards.asp?lngWId=5)
Advertising/Media kit (http://domain.com/vb/advertisement/scripts/rates.asp?lngWId=5)
Feedback (http://domain.com/vb/feedback/feedback.asp?lngWId=5)
About the site (http://domain.com/vb/about/AboutTheSiteAndAuthor.asp?lngWId=5)
Goto…
By using this site you agree to its Terms and Conditions (http://domain.com/vb/scripts/TermsAndConditions.asp?lngWId=5) . Planet Source Code™ and the
phrase "Dream It. Code It"™ are trademarks of Exhedra Solutions, Inc. (http://www.exhedra.com/)
15 of 15 6/13/2011 10:10 AM