强制转换值SQL IN函数 [英] casting values SQL IN function

查看:89
本文介绍了强制转换值SQL IN函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在将nvarchar参数传递给存储过程时遇到了这个问题,并且该参数在表中的字段类型是int.我这样做是因为我正在使用IN函数,例如,如果要发送多个参数,那是通过.NET进行操作的唯一可能方法.或不?由于类型错误,SP无法执行,我正在尝试强制转换该值,但出现错误.这是我的尝试方式:

Hello,

I have this problem where I am passing nvarchar parameter to a stored procedure, and the field type in the table for that parameter is int. I am doing that because I am using IN function, and for example if I want to send multiple parameters, that is the only possible way to do through .NET. Or not? The SP doesn''t get executed because of the wrong type, and I am trying to cast the value, but I get an error. Here is how I am trying:

Example: @Parameter nvarchar OrderStatusID = (''30, 40'')
(o.OrderStatusID IN (CAST(@OrderStatusID as int)) OR @OrderStatusID IS NULL)


有没有一种方法可以分别转换每个值,或者将完整值转换为int的最佳方法是什么?在此先感谢您的帮助.


Is there a way to cast each value separately, or what will be the best way to cast whole value as int. Thanks in advance for your help

推荐答案

这是一个很好的示例,说明了如何在SQL中拆分值.甚至不应该考虑第一种方法,因此只需跳过该方法即可.方法6可能是最适合您的示例.

http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm [
Here is a good example how to split the values in SQL. The first method shouldn''t even be considered so just skip that. Method 6 would probably be the best example for you.

http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm[^]

Good luck!


这篇关于强制转换值SQL IN函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆