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.
| 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 inserting2. The phone number is uniqueElse, 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 pageAny advice ??? ThanksAfrika |
|
|
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. |
 |
|
|
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 pageOr get my web page to read this error ??? |
 |
|
|
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 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-27 : 07:45:12
|
| Create sp with output parameterIn your webpage use an object of type ADODB.Command and get the returned value of sp using parameters method of that objectMadhivananFailing to plan is Planning to fail |
 |
|
|
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, madhivananAfrika |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
|
|
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 inserting2. The phone number is uniqueElse, 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 pageAny advice ??? ThanksAfrika
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)ASDECLARE @userNameStat INTDECLARE @phoneNumberStat INTSET @userNameStat = 0SET @phoneNumberStat = 0--- First Check the UserName-- Create a UDF that checks the username is exist; returns 0 if not duplicate and returns 1 if duplicateIF (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 duplicateIF (select dbo.CheckPhoneNumber(@phoneNumber)=1) SET @phoneNumberStat = 1--FINALLY INSERT IF BOTH CONDITIONS HAVE 0 Value means no DuplicateIF ((@userNameStat=0) AND (@phoneNumberStat=0)) BEGIN INSERT INTO YourTableName VALUES (Value1,Value2) -- set the return value to 0, meaning successful SET @RetStatus = 0 ENDELSE 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 rockmoosehttp://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 |
 |
|
|
|
|
|
|
|