如何在SQL函数中将多个值传递给单个参数?

时间:2015-12-23 08:46:54

标签: sql sql-server sql-server-2008 function

这是变量的声明方式:

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) = '') 

当我以这种方式执行时,该功能正常工作:

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

但现在我想传递多个关系,如下所示:

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

那我怎么能这样做呢?

1 个答案:

答案 0 :(得分:0)

像Giorgos所说的Table-Valued Parameter.you可以像这样声明

    declare @relationship table (relationship varchar(100))
    INSERT INTO @relationship(relationship) values('Roommate');