Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to write function of selecting one value like userid in store procedure....
Posted
Comments
AmitGajjar 28-May-12 1:34am    
if you would like to return some value, you can use OUT variable. why you want function for selecting a value if you already have SQL query?
Prosan 28-May-12 5:49am    
i am just answering the question? it is not my opinion it is solution of question

like that you can select value by calling function from stored procedure

SQL
ALTER PROC [dbo].[USP_StoreProcedureName]
(
	@UserId int=0
)
AS
BEGIN
select dbo.Fun_FunctionName(@UserId)
end

--- function description 
ALTER Function  [dbo].[Fun_FunctionName]
(
	@UserId int=0
)
Returns  varchar(50)
AS
Begin
DECLARE @ReturnValue VARCHAR(20)
  --now set this variable as you like
  
 set @ReturnValue ---- your logic
return  @ReturnValue
end
 
Share this answer
 
Comments
Maciej Los 29-May-12 4:57am    
Good answer, my 5!
Do you really mean a function or just how to select something in a stored procedure.

The simplest way is to just execute the query, like:
SQL
CREATE PROCEDURE abc
AS BEGIN
   SELECT ... FROM TheTable WHERE ...;
END;

Refer to CREATE PROCEDURE [^]
 
Share this answer
 
Hi,

You cannot define function in stored procedures.

Best Luck
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900