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
 Transact-SQL (2000)
 How do i return a status to a web page

Author  Topic 

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-05-27 : 06:56:31
hello,
how do i return an output status to a web page from an SP ?

Bascially, i am trying to create a signup page that uses a SP for inserts and later updates ( when choosing a username and password)

I would need to check to see if;
1. The username exists before inserting
2. The phone number is unique

Else, alert the user and ask him to choose another.

This is where i need to pass an output parameter, or an error message with a return value to my web page

Any advice ???

Thanks
Afrika

nr
SQLTeam MVY

12543 Posts

Posted - 2005-05-27 : 07:14:58
Probably best to use an output parameter although you can use a return code.
Use raiserror for errors.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-05-27 : 07:17:51
Ok thanks Nigel, Now how do i pass this to my web page

Or get my web page to read this error ???
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-05-27 : 07:43:14
The link I posted in this thread shows how to use output parameters in ASP:
[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50331[/url]

You are not getting it to work ?

rockmoose
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-05-27 : 07:45:12
Create sp with output parameter
In your webpage use an object of type ADODB.Command
and get the returned value of sp using parameters method of that object

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-05-27 : 16:56:34
Funny, this page didnt give me the opportunity to subscribe to it, neither informed me i had replies.

Just saw all your threads rockmoose. I wonder why i never got a reply. thanks rockmoose, madhivanan

Afrika
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-05-27 : 17:08:32
Afrika, subscriptions have been (or at least were) turned off for a little while by Graz while. They were affecting performance of the whole site. See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50337 for more info.

---------------------------
EmeraldCityDomains.com
Go to Top of Page

raclede
Posting Yak Master

180 Posts

Posted - 2005-05-29 : 20:51:56
quote:
Originally posted by afrika

hello,
how do i return an output status to a web page from an SP ?

Bascially, i am trying to create a signup page that uses a SP for inserts and later updates ( when choosing a username and password)

I would need to check to see if;
1. The username exists before inserting
2. The phone number is unique

Else, alert the user and ask him to choose another.

This is where i need to pass an output parameter, or an error message with a return value to my web page

Any advice ???

Thanks
Afrika



1. Well Create an SP for insert well lets say


CREATE PROCEDURE AccountInsProc
(
@userName varchar(150),
@phoneNumber varchar(50),
@RetStatus int OUTPUT
-- Returns 0 for Successful insert
-- Returns 1 for Duplicate userName
-- Returns 2 for Duplicate phoneNumber
-- Returns 3 for Duplicate userName & phoneNumber
)
AS
DECLARE @userNameStat INT
DECLARE @phoneNumberStat INT

SET @userNameStat = 0
SET @phoneNumberStat = 0

--- First Check the UserName
-- Create a UDF that checks the username is exist; returns
0 if not duplicate and returns
1 if duplicate
IF (select dbo.CheckUserName(@userName)=1) SET @userNameStat = 1

--- Second Check the PhoneNumber
-- Create a UDF that checks the PhoneNumber is exist; returns
0 if not duplicate and returns
1 if duplicate
IF (select dbo.CheckPhoneNumber(@phoneNumber)=1) SET @phoneNumberStat = 1

--FINALLY INSERT IF BOTH CONDITIONS HAVE 0 Value means no Duplicate
IF ((@userNameStat=0) AND (@phoneNumberStat=0))
BEGIN
INSERT INTO YourTableName
VALUES (Value1,Value2)
-- set the return value to 0, meaning successful
SET @RetStatus = 0
END
ELSE
BEGIN
-- Test the Status of username and phonenumber
SET @RetStatus = ( CASE
--both duplicates
WHEN (@phoneNumberStat = 1 AND @userNameStat=1)
THEN 3
WHEN (@phoneNumberStat = 1)
THEN 2
ELSE 1
END
)
END
RETURN

--2 sample UDF
CREATE FUNCTION CheckUserName
(
@userName varchar(150)
)
RETURNS INT AS
BEGIN
DECLARE @RetStat INT
DECLARE @Result INT

SET @Result = (Select Count(UserName) from Account where
username = @userName)

-- already exists
IF @Result > 0 SET @RetStat = 1
ELSE SET @RetStat = 0


RETURN @RetStat

END




FOR How to use OUTPUT parameter check this link by rockmoose
http://www.asp101.com/articles/wrox/asp30/26100903.asp

"If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside. "

raclede
Go to Top of Page
   

- Advertisement -