简体   繁体   English

INSERT INTO @Temp_Table VALUES 从多值 SSRS 参数

[英]INSERT INTO @Temp_Table VALUES from multi value SSRS Parameter

i'm building a report using ssrs report builder where in the code there is a part where i have to insert into a temp table some values.我正在使用 ssrs 报告生成器构建报告,其中在代码中有一部分我必须将一些值插入到临时表中。 these values should be loaded from a multi value parameter DatabaseName.这些值应该从多值参数 DatabaseName 加载。 i tried the below code:我尝试了以下代码:

DECLARE @Rep_Temp TABLE(SurrogateKeyIDENTITY int not null IDENTITY (1,1),tempDBName nvarchar(100) NOT NULL);
INSERT INTO @Rep_Temp (tempDBName) VALUES (@DatabaseName);

it works only if i select one value, when i select multiple value it will give error.只有当我选择一个值时它才有效,当我选择多个值时它会出错。

i also tried the below code with no success:我也尝试了以下代码但没有成功:

INSERT INTO @Rep_Temp (tempDBName) VALUES (join(Parameters!DatabaseName.Value,","));

appreciate your assistance.感谢您的帮助。

Best regards,此致,

I solve it as per the below:我按照以下方法解决:

  1. I added Parameter in the dataset: @DBNameString = join(Parameters!DatabaseName.Value,",")我在数据集中添加了参数: @DBNameString = join(Parameters!DatabaseName.Value,",")
  2. I tried to use STRING_SPLIT when inserting the table but i couldn't due to the fact that i have SQL Server 2012 "is not a recognized built-in function name".我在插入表时尝试使用 STRING_SPLIT 但我不能,因为我有 SQL Server 2012“不是公认的内置函数名称”。 instead i did the following:相反,我做了以下事情:

DECLARE @Rep_Temp TABLE(SurrogateKeyIDENTITY int not null IDENTITY (1,1),tempDBName nvarchar(100) NOT NULL);声明@Rep_Temp TABLE(SurrogateKeyIDENTITY int not null IDENTITY (1,1),tempDBName nvarchar(100) NOT NULL);

DECLARE @DBs VARCHAR(500);
DECLARE @DBName VARCHAR(500);
DECLARE @charSpliter CHAR;

SET @charSpliter = ','
SET @DBs = @DBNameString + @charSpliter;

WHILE CHARINDEX(@charSpliter, @DBs) > 0
BEGIN
SET @DBName = SUBSTRING(@DBs, 0, CHARINDEX(@charSpliter, @DBs))
SET @DBs = SUBSTRING(@DBs, CHARINDEX(@charSpliter, @DBs) + 1, LEN(@DBs))

INSERT INTO @Rep_Temp (tempDBName) VALUES (@DBName);    
END 

Best Regards,此致,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM