Call A function in Stored procedure

step 1> Create a table which have username and password and so on.

Step 2> Create a function using given query.

create function function_to_be_called(@username varchar(200))
returns varchar(100)
as
begin
declare @password varchar(200)
set @password=(select [password] from [User] where username =@username)
return @password
end


step 3> Create a function using given query...

create procedure chek_pass
@user varchar(200)
as
begin
declare @pass varchar(200)
set @pass=dbo.function_to_be_called(@user)
select @pass
end


Step 4> Check it ..

exec chek_pass 'username'

Step 5 > Enjoy the Code.


This is a simple query, you can try it for more complex query and can remove many steps of your Front End programming code.

It always helps and Optimize your code.