简体   繁体   English

将多个nvarchar值转换为int

[英]Convert multiple nvarchar values to int

I'm working on an SSRS report where users can type in multiple numbers to bring back relevant data. 我正在编写一份SSRS报告,用户可以输入多个数字来恢复相关数据。 The requirement is to enable users to be able to input multiple values. 要求是使用户能够输入多个值。

So I have a param @serial which can either me just one value or anything upto 100 所以我有一个参数@serial ,它可以只是一个值或任何高达100的值

I can't seem to figure out how to convert each value from nvarchar to int 我似乎无法弄清楚如何将每个值从nvarchar转换为int

I've tried SET @Serials = CONVERT(INT,@Serials) but I get the following error message 我试过SET @Serials = CONVERT(INT,@Serials)但是我收到以下错误信息

Conversation fail when converting the nvarchar value '123 456' to data type int nvarchar值'123 456'转换为数据类型int时,会话失败

If I use @serial as int then I get the following error message 如果我使用@serial作为int然后我收到以下错误消息

There are fewer columns in the INSERT statement than values spevified in the VALUES caluse. INSERT语句中的列数少于VALUES caluse中的值。 The number of values in the VALUES caluse must match the number of columns specified in the INSERT statement VALUES caluse中的值数必须与INSERT语句中指定的列数相匹配

The error above is when I'm inserting into a temp table at the below line of code 上面的错误是当我在下面的代码行插入临时表时

INSERT INTO @Temp
(TMP_SerialNo)
VALUES (@serial)

If someone guide me where I'm going wrong I would greatly appreciate it 如果有人指导我出错的地方,我会非常感激

The easiest way to do this in an SSRS report is to add a cast to put it in int. 在SSRS报告中执行此操作的最简单方法是添加强制转换以将其置于int中。 You can't insert values into a SSRS report, only a SQL Table. 您不能将值插入SSRS报告,只能插入SQL表。

I add this at the beginning (before the select): 我在开头添加它(在选择之前):

  DECLARE @temp_Status integer;
    set @temp_Status = CAST(SomeStatus as int);
    And then use everywhere the var @temp_Status.

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

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