2

This is how variables are declared:

CREATE FUNCTION Fn_custom_roomie_emails
(@htenant       NUMERIC(18), 
 @dtmoveout     DATETIME, 
 @lesseeonly    VARCHAR(3)= 'NO', 
 @relationship  VARCHAR(100),
 @listseparator VARCHAR(10) = '; ', 
 @nameseperator VARCHAR(10) = ', ', 
 @andfunction   VARCHAR(3) = 'NO', 
 @tenantemail   VARCHAR(100) = '') 

The function works fine when I execute in this way:

exec dbo.Fn_custom_roomie_emails(hmy, Getdate(), 'All', **'Roommate'**, ';', ' ', '', 'YES')

But now I want to pass multiple relationships as shown below:

exec dbo.Fn_custom_roomie_emails(hmy, Getdate(), 'All', **'Roommate', 'Guarantor'**, ';', ' ', '', 'YES')

So how can I do that?

5
  • 2
    Use a Table-Valued Parameter Commented Dec 23, 2015 at 8:50
  • Is this mysql or sql server? Commented Dec 23, 2015 at 8:52
  • you can send values comma-seprated and then split it into function Commented Dec 23, 2015 at 8:52
  • Giorgos: So you mean I should store this relationships in table and pass that table to function? Commented Dec 23, 2015 at 9:02
  • Have a look here Commented Dec 23, 2015 at 9:05

1 Answer 1

0

like Giorgos said Table-Valued Parameter.you can declare like this

    declare @relationship table (relationship varchar(100))
    INSERT INTO @relationship(relationship) values('Roommate');
Sign up to request clarification or add additional context in comments.

1 Comment

It's not that simple. What you've shown here is a table variable, which you can't pass as a parameter. You need to define a table type first, then you can declare it, insert data into it, and finally pass it as a parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.