Groups | Blog | Home
all groups > sql server programming > april 2005 >

sql server programming : Website imput into sql database


HollyylloH
4/9/2005 11:53:02 PM
I have a web form (ASP) that imputs into a sql database. I need to return a
value based on the values a user enters.

The user would choose a "size" and then choose a "packaging"

I have a table that has three columns "size" "packaging" and "cost"

I need to have the cost value returned based on the values the user chooses
for "Size" and "packaging"

For example:

If the user chooses "32" as the size
and
chooses "plastic" as the packaging
(there is, in every case, only one value in my table that would meet both
these chriteria)
I need the "Cost" field to automatically have a value 3.00 returned from the
table.

I am new to SQL so if you could offer as much detail as possible it would be
much appreciated.

Thank you

Trond
4/10/2005 12:00:00 AM
I assume you are using an SQL2000 server. Also i assume you are using ASP
and NOT ASP.NET.
In your form you select some values (or type them in). 32 and plastic.
Then the user click a submit button?
Will the user then end up in a new form? If so i would do it like this:

I would create a SPROC on the SQL server.
CREATE PROCEDURE getMyNumber @Number int, @Type varchar(50)
AS
SELECT IDW
FROM MyTable
WHERE (Number = @Number) AND (Type = @Type)

The SPROC is having 2 parameters, @Number is 32 in this case and @Type is
Plastic

The SPROC returns a number :-)
I did not add error handling to this SPROC. I could to a IF EXISTS just in
case.
Like this:
IF EXISTS(SELECT IDW FROM MyTable WHERE (Number = @Number) AND (Type =
@Type))

If you need code to use this sproc i can help you if you need to. Just post
in this group tho

Best regards
Trond

[quoted text, click to view]

HollyylloH
4/10/2005 5:27:02 PM
Trond,
Thanks, this got me started. I can use further help. Yes, I am using SQL2000
and ASP

I created the getmynumber procedure as you suggested and it appears I got
the syntax correct. I need to know now how to get it to run either with a
submit button or perhaps after both "size" and "packaging" have been selected
by th user.

I tried attaching the EXECUTE statement to the "Cost" field in my form but
it doesn't run.

Here is what I have so far:

CREATE PROCEDURE getmynumber @size nvarchar(50), @packaging nvarchar(50)
AS
SELECT Cost
FROM Cost
WHERE (Size = @size) AND (Packaging = @packaging)

and

EXECUTE getmynumber @size = [Size], @packaging = [Packaging]

Do I need to create an INPUT , OUTPUT , or RETURN VALUE procedure?

Thank you

[quoted text, click to view]
AddThis Social Bookmark Button