We will create a function that merge two string value and returns it. It is a simple example. There is a function in sql merges two values named concat. We use + operator to merge two strings.
1 2 3 4 5 6 7 |
Create function myMerge(@v1 varchar(30),@v2 varchar(30)) returns varchar(max) as Begin return @v1 + ' '+@v2 End |
After running the code above we will get succesfull message than we can run the code below:
Example
1 |
Select dbo.myMerge('Mike','Brown') |
Result: Mike Brown
Example in a query
1 |
Select dbo.myMerge(name,surname) from students |
Result:
CLICK HERE TO SEE MORE EXAMPLE ABOUT SCALAR VALUED FUNCTIONS