check a duplicates user_name value in database

Posted by Bhuwan87rawat under ASP.NET on 8/23/2012 | Points: 10 | Views : 2276 | Status : [Member] | Replies : 5
Hi
In my application i want to check a duplicates user_name value in database with help of store
procedure . it is possible...


Regard

Bhuwan




Responses

Posted by: Nadh123 on: 8/23/2012 [Member] Starter | Points: 25

Up
0
Down

CREATE PROC PR_GET_CHECK_USER_NAME
(
@IP_USER_NAME VARCHAR(26),
@OP_RETURN_MSG VARCHAR(100) OUTPUT
)
AS
/* EXECUTION
DECLARE @X VARCHAR(100)
EXEC PR_GET_CHECK_USER_NAME 'USERNAME' ,@X OUTPUT
SELECT @X AS RETURNMESSAGE */

BEGIN
DECLARE @LV_USER_ID INT

SELECT @LV_USER_ID =[USER_ID]
FROM USERS
WHERE [USER_NAME]=@IP_USER_NAME
IF @LV_USER_ID >0
BEGIN
SET @OP_RETURN_MSG= 'USER IS EXISTS'
END
ELSE
BEGIN
SET @OP_RETURN_MSG= 'USER IS NOT EXISTS'
END
END

Mahendra
91-9908699686

Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhuwan87rawat on: 8/23/2012 [Member] Starter | Points: 25

Up
0
Down
sir in my application i make a registration form and i check the username already exist in database with the help of
store procedure.....

Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 8/24/2012 [Member] Starter | Points: 25

Up
0
Down
ALTER PROCEDURE [dbo].[USP_NewUserRegistration]
(
@strUserName nvarchar(50),
@strFirstName nvarchar(50),
@strEmail nvarchar(50),
@strPassword nvarchar(50),
@iAge int,
@strCity nvarchar(50),
@iPhoneNo numeric

AS
BEGIN
DECLARE @UID INT=0
IF @strusername NOT IN (SELECT UserName from userRegistrationTB)
BEGIN

INSERT INTO userRegistrationTB
(
username,
firstname,
lastname,
useremail,
[password],
age,
city,
phone,
CreatedDate

)
VALUES
(
@strUserName,
@strFirstName,
@strEmail,
@strPassword,
@iAge,
@strCity,
@iPhoneNo,
GETDATE()
)
END
ELSE
BEGIN
SELECT 'user already exists pleae choose different username'
END

SET NOCOUNT ON;
END



Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nkkppp on: 8/24/2012 [Member] Starter | Points: 25

Up
0
Down
Simple stored procedure to check duplicate Username

@username parameter will the textbox value from the front end

Create Procedure Check_Username(@username)
as
Begin
if Not exists(select * from Users where username=@Username)
Insert into Users values(@username)
End

In the front end take a variable i and write the foll code
Sqlcommand cmd;
int i=cmd.ExecuteNonquery();

if(i>0)
Enter into the Main page of Website

else
label1.text="User already exists";





Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Maheshvishnu on: 9/7/2012 [Member] Starter | Points: 25

Up
0
Down
create procedure check_user(@userid varchar(50))
as
begin
if exists(select * from table where userid=@userid)_
return false;
else
print 'no records exists for given userid'
end

mahesh

Bhuwan87rawat, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response