Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to use stored procedures

Author  Topic 

Pumpkins_Man
Starting Member

20 Posts

Posted - 2002-04-02 : 20:58:13
hey guys, i'm a newbie to stored procedures and i really have no idea how to pass variables to them and how to retrieve values back from a stored procedure.

i've used asp and sql server before but i've never wanted to use stored procedures until now.

i was hoping if i show you guys a quick example of something i would like to try and use a stored procedure for then hopefully you can help me start my learning curve.

example:
i would like to get an account_Name from a user and then check a table called Users to find out the User_ID that corresponds with that account_Name. in asp i could achieve this by creating a form:
 <form name="frmLogin" method="get" action="userid2.asp">
<table width="22%" border="0">
<tr>
<td width="8%">Username:</td>
<td width="92%">
<input type="text" name="Account_Name">
</td>
</tr>
<tr>
<td width="8%"> </td>
<td width="92%">
<input type="submit" name="Submit" value="Login">
</td>
</tr>
</table>
</form>


then that sends my Account_Name variable to a userid2.asp page and on that page i qould have the following code:

%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/DSNIntranet.asp" -->
<%
Dim myvar
myvar = "1"
if (Request.QueryString("Account_Name") <> "") then myvar = Request.QueryString("Account_Name")
%>
<%
set rsTest = Server.CreateObject("ADODB.Recordset")
rsTest.ActiveConnection = MM_DSNIntranet_STRING
rsTest.Source = "SELECT User_ID, Account_Name FROM dbo.Users WHERE Account_Name = '" + Replace(myvar, "'", "''") + "'"
rsTest.CursorType = 0
rsTest.CursorLocation = 2
rsTest.LockType = 3
rsTest.Open()
rsTest_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<%=(rsTest.Fields.Item("User_ID").Value)%>
</body>
</html>
<%
rsTest.Close()
%>


i know thats simple enough there and i am pretty sure that i could use the following stored procedure:
 
Create procedure Retrieve_User_ID
@accountName varchar(16),
@userID int = 0 output

As
Select @userID = [User_ID] from Users
where Account_Name = @accountName


GO
but i don't know how i send or receive values.

i hope one of you guys can point me in the right direction cause i'm so confused it's not funny. *gets on knees and begs* please can someone help me out. if anyone knows of a really simple tute and sends me a link to that i'd be more than happy.
thanking you in advance,

bronson

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-04-02 : 23:38:06
Hi there

Go have a read of this article
http://www.aspalliance.com/stevesmith/articles/sprocs.asp

If you are still confused, come back and let us know and we can go from there

Good luck



Damian
Go to Top of Page

Pumpkins_Man
Starting Member

20 Posts

Posted - 2002-04-03 : 00:05:34
Thankyou sssssooooo much Merkin.
Thats exactly the sort of tute I was after. I had a feeling it was going to be fairly simple and I thought that it would be fairly easy to find a tute on the basics of stored procedures but all the ones i found (and god i foudn stacks of them) all seem to step over the basic and into the harder stuff.
Anyways I'm going to see if I can get to learn a stack more on them now.
Thanks a billion Merkin...no doubt I'll be back bugging the guys on this board when i get stuck.

http://www.users.bigpond.com/thefullmontybronty
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-04-03 : 00:17:11
Hey, another Aussie. I didn't notice before
How is Brissy ?

Damian
Go to Top of Page

Pumpkins_Man
Starting Member

20 Posts

Posted - 2002-04-03 : 00:54:35
haha i figured that they only readon you reply to me was cause i was an aussie too hehe
yeah things in brissy aren't too bad at all. the weathers not so great but i guess that doesn't really matter cause i'm inside messing with stored procedures

http://www.users.bigpond.com/thefullmontybronty
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-04-03 : 02:40:18
not only an aussie - but a muso too.

(Think I'll go buy a lottery ticket)

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

Pumpkins_Man
Starting Member

20 Posts

Posted - 2002-04-03 : 17:13:03
You betcha. I couldn't live without music. what music are you into rrb? what instruments do you play?
i play oboe, clarinet, guitar and i've been practicing beat mixing with vinyls.

http://www.users.bigpond.com/thefullmontybronty
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-04-08 : 01:48:23
Wow - a pumpkin that plays clarinet! Obviously only in QLD.

I beat the skin, twang the string, like to harmonise the ebony and ivory and (occasionally) do a rebel yell.

Actually I don't listen to music much - I like to play

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -