Require StoredProc
-
Hi, i want to insert some users in a table. before inserting those users i want to check that user is already exists or not. so i want to written one sp.can any one please help me by posting some sample Storedproc
fttyhtrhyfytrytrysetyetytesystryrty
-
Hi, i want to insert some users in a table. before inserting those users i want to check that user is already exists or not. so i want to written one sp.can any one please help me by posting some sample Storedproc
fttyhtrhyfytrytrysetyetytesystryrty
Here it is!
create procedure InsertUser
@username varchar(200)
as
Begin
if(select count(*) from users where username=@username) = 0)
begininsert into users values(column1,column2......)
end
end
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Hi, i want to insert some users in a table. before inserting those users i want to check that user is already exists or not. so i want to written one sp.can any one please help me by posting some sample Storedproc
fttyhtrhyfytrytrysetyetytesystryrty
Hi , Thanks for reply in this stored proc i want to return some value. so that i can handle in my C# sharp code. i this case i want else condition and some return value
fttyhtrhyfytrytrysetyetytesystryrty
-
Hi , Thanks for reply in this stored proc i want to return some value. so that i can handle in my C# sharp code. i this case i want else condition and some return value
fttyhtrhyfytrytrysetyetytesystryrty
Then I will suggest you to use function
create function InsertUser
@username varchar(200)
as
Beginreturn 0 --By default user is not inserted and return value have value 0
if(select count(*) from users where username=@username) = 0)
begininsert into users values(column1,column2......)
return 1 --User is inserted and return value have value 1end
end
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Hi, i want to insert some users in a table. before inserting those users i want to check that user is already exists or not. so i want to written one sp.can any one please help me by posting some sample Storedproc
fttyhtrhyfytrytrysetyetytesystryrty
Try this CREATE PROCEDURE [dbo].[USP_CheckUserAvailability] -- Add the parameters for the stored procedure here ( @UserName AS VARCHAR(50) ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here IF EXISTS( SELECT [User Name] FROM tbl_User WHERE [User Name] = @UserName ) BEGIN SELECT * FROM tbl_User END ELSE INSERT INTO tbl_User ([User Name]) VALUES (@UserName) END Hope this helps :)
Niladri Biswas