Question: SQL Server comes with a number of string functions, such as RIGHT(), which accepts an Expression as a parameter so that it can accept either a varchar or nvarchar value.

How do I create my own custom function to do the same?

I am not a SQL Server expert, so a simple example with syntax would help.

Thank You

Answer: 
Here is a simple example:

```
CREATE FUNCTION myUDF (@input nvarchar(255))
RETURNS nvarchar(255)
AS
BEGIN
            -- function logic here
            declare @output nvarchar(255)
            select @output = 'The value passed in was: ' + @input
            return @output
End

GO    

select dbo.myUDF('I wrote a function!')

```
Here you can try this way.

[How to: Create and Run a CLR SQL Server User-Defined Function](http://msdn.microsoft.com/en-us/library/w2kae45k%28v=vs.80%29.aspx)