Userdefinedfunctions
User defined functions are 3 types. 1.SCALAR FUNCTION 2.INLINE TABLE VALUED FUNCTION 3.MULTI SATATEMENT TABLE VALUED FUNCTIONS
SCALAR FUNCTION :¶
Scalar functions may or may not have parameters ,but always returns a single value ,the returned value can be any data type .
1 2 3 4 5 6 7 8 9 10 11 12 | |
ex:
1 2 3 4 5 6 7 8 9 | |
INLINE TABLE VALUED FUNCTION :¶
It returns table it means single select query result only. there is no begin and end end block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
ex:
1 2 3 4 5 6 7 8 9 10 11 | |
MULTI SATATEMENT TABLE VALUED FUNCTIONS :¶
Multi satatement table valued functions are very similar to inline table valued functions
1.Inline table valued function can not return return table with structure where as Multi satatement table valued functions can return table variable with structure
2.There is no begin and end block in Inline table valued function where as Multi satatement table valued functions have begin and end block
3.After creation of both inline and multi statement table valued functions, then those functions acts as tables ,we can update the data in table (inline table valued function) but we can not update the data in table (multi satetement table function).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
ex:
```
CREATE FUNCTION fn_getemployeebyjobs
(
@job varchar(50)
)
RETURNS
@table TABLE
(
-- Add the column definitions for the TABLE variable here
1 | |
END