0

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?

1 Answer 1

1

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; 
Sign up to request clarification or add additional context in comments.

2 Comments

Hey Gordon! Thank you! And how would it look like if @name would be a column in a table?
@not_ur_avg_cookie . . . Then you would call the function in a select query referring to that table and column.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.