views:

31

answers:

3

i need thing like set @var= exec calculate 'param' are this true

A: 

You should be using output parameters for the stored procedure:

DECLARE @output1 INT
EXEC [proc] @input, @output1 OUTPUT

PRINT @output1
spinon
+2  A: 
DECLARE @ret INT
DECLARE @output INT

EXEC @ret = [proc] @input, @output OUTPUT

SELECT @ret, @output

@ret is the return value: RETURN -1
@output is an assignable variable of any type: SET @output = 123

Scoregraphic
A: 

A function is a good place to perform a commonly used calculation.

CREATE FUNCTION dbo.ufnAddIntegers
    (@pint1 as int, @pint2 as int)
RETURNS int
AS
BEGIN
   return @pint1 + @pint2
END
go

declare @intResult int
set @intResult = dbo.ufnAddIntegers(3, 4)
select Result = @intResult

/*
Result
-----------
7
*/
thanks @peterellis its good solution.put whats diffrence between functions and stored procedure
shmandor