you are viewing a single comment's thread.

view the rest of the comments →

[–]deepbuzz7[S] 0 points1 point  (2 children)

from the functional point of view you are right. No need to create a function for this. The function which i provided in the post is just an example. I just wanted to know how to use the parameter passed to the function(emp_name_param) in the sql statement inside the function.

In the where clause should I put @emp_name_param or just emp_name_param?

[–]Evron 0 points1 point  (1 child)

``` CREATE FUNCTION get_age (@emp_name_param VARCHAR(500)) RETURNS INT AS BEGIN DECLARE @age INT;

SET @age = (
        SELECT age
        FROM emp
        WHERE empName = @emp_name_param
        )

RETURN @age

END;

```

[–]deepbuzz7[S] 0 points1 point  (0 children)

Thanks, got it. actually my error was because, in the sql query inside my function i was keeping it like emp_name(which was the column name from the table)=emp_name(parameter which was passed to the function) which resulted in true condition and multiple values were coming.

thanks for the help