not_ur_avg_cookie
not_ur_avg_cookie

Reputation: 333

Create scalar function with declared variables

I have a verify simple query in which I have a variable declared. I would like to create a scalar function that automatically converts whatever I write into the variable, into my finished string:

declare @name varchar(100) = 'firstnameLastname'

select @name + '@email.com'

My goal is to use this function with a random string which converts it automatically into my Email String. For example:

select udfEmailConversion('RobertSequel')

and it should automatically return:

[email protected]

How can create a scalar function when I have variables declared in my query?

Upvotes: 0

Views: 639

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271241

If you are asking about how to define a function, the syntax looks like:

create function udfEmailConversion (
    @base nvarchar(255)
) 
returns nvarchar(255)
as 
begin
     return @base + '@email.com'
end;

Upvotes: 1

Related Questions