关于sql where id in 转换成数据类型 int 时失败(转)
有执行sql条件语句where id in(@参数)的时候,如果处理不当,就会出现问题:
如下面这个存储过程:
alter proc Web_gettwtwgoldgameserverGoldSell
@ID int
as
declare @twgoldsellID nvarchar(1000)
select @twgoldsellID=twgoldsellID from twgoldgameserver where ID=@ID
set @twgoldsellID=replace(@twgoldsellID,'|',',')
set @twgoldsellID=left(@twgoldsellID,len(@twgoldsellID)-1)
select * from twgoldsell where ID in (@twgoldsellID)
我们看上去好像没有什么问题,却在执行的时候报错:
消息 245,级别 16,状态 1,第 1 行
在将 varchar 值 '813,1160,1219,1227,1232' 转换成数据类型 int 时失败。
其实此条语句在执行时,
select * from twgoldsell where ID in (@twgoldsellID)
执行的语句是:select * from twgoldsell where ID in ('813,1160,1219,1227,1232')
这样执行当然出错,因为@twgoldsellID是一个字符串,现在是以参数的形式传递。
解决办法:
select * from twgoldsell where ID in (@twgoldsellID)
改为:
exec('select * from twgoldsell where ID in ('+@twgoldsellID+')')
记住:一定要加exec执行函数,不然会报如下错误:
消息 245,级别 16,状态 1,过程 Web_gettwtwgoldgameserverGoldSell,第 8 行
在将 varchar 值 '+@twgoldsellID+' 转换成数据类型 int 时失败。
关于sql where id in 转换成数据类型 int 时失败(转)的更多相关文章
- sql 在将 nvarchar 值 转换成数据类型 int 时失败。
假设有存储过程:proc_test2 create proc proc_test2 @Id int begin as declare @sql varchar(max) @sql = 'select ...
- 佩特来项目经验小集合(2)___组合查询存储过程,报错 "varchar JBID='' 转换成数据类型 int 时失败"
今天写一个组合查询的存储过程遇到这样一个问题:在将 varchar 值 'SELECT * FROM View_DLS_WXJD_Customer WHERE 1=1 and JBID ='' ...
- 在将 varchar 值 '2,7' 转换成数据类型 int 时失败
消息 245,级别 16,状态 1,第 1 行在将 varchar 值 '2,7' 转换成数据类型 int 时失败. 原sql select UserName from s_User where ...
- 在将 varchar 值 '1,2,3,4,5,6,7,8' 转换成数据类型 int 时失败。
alter PROCEDURE PrTradingDelete ) AS BEGIN WHERE id in(@id) END GO 执行上面这个存储过程会异常.提示 :在将 varchar 值 '1 ...
- 将 varchar 值 'ACCE5057EC423F7C' 转换成数据类型 int 时失败
调试别人的存储过程,然后报错了 将 varchar 值 'ACCE5057EC423F7C' 转换成数据类型 int 时失败 这让我一通找.找了一个多小时. 通过这个错可以知道,错误肯定是在联表 字段 ...
- 消息 245,级别 16,状态 1,第 1 行 在将 varchar 值 '2,8' 转换成数据类型 int 时失败。
错误问题: 消息 245,级别 16,状态 1,第 1 行在将 varchar 值 '2,8' 转换成数据类型 int 时失败. ps: 这是在后台分配菜单权限这个功能时出现的问题 一,解决方法: 将 ...
- MSSQL 错误:在将 varchar 值 '1,2,3,5,6' 转换成数据类型 int 时失败。
MSSQL 错误:在将 varchar 值 '1,2,3,5,6' 转换成数据类型 int 时失败.
- sql in(1,2,3)参数化查询,错误在将 varchar 值 '1,2,3,4' 转换成数据类型 int 时失败
解决办法 string userIds = "1,2,3,4";using (SqlConnection conn = new SqlConnection(connectionSt ...
- 在将 varchar 值 '' 转换成数据类型 int 时失败
我们有时候用in语句的时候,发现存在Sql注入漏洞,想参数化处理一下,遇到语句执行问题!! declare @ids varchar() set @ids='216,218' select * fro ...
随机推荐
- Linux 常用
1,解决ssh登录慢的问题记录 vim /etc/ssh/ssh_config # GSSAPIAuthentication no 把下面这一行的注释去掉 2,Linux查看当前是什么系统 ...
- Problem A 栈
Description You are given a string consisting of parentheses () and []. A string of this type is s ...
- 移动设备和SharePoint 2013 - 第3部分:推送通知
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
- ios 检测应用程序升级问题
app 上其实已经有自动检测我们版本的功能. 其实我也觉得对于一个程序员来说检测功能让,系统来维护更合适和合理.开发者只要告诉苹果即可. 然而今天老大非要实现自己版本更新的问题,因此也查找了相关的资 ...
- Math 对象的方法
Math 对象的方法 方法 描述 abs(x) 返回数的绝对值 acos(x) 返回数的反余弦值 asin(x) 返回数的反正弦值 atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返 ...
- jsunit测试
var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/ba ...
- (转)iphone数据存储之-- Core Data的使用
原文:http://www.cnblogs.com/xiaodao/archive/2012/10/08/2715477.html iphone数据存储之-- Core Data的使用(一) 一. ...
- java generic type
java generic type: 类型安全.类型参数化.不需要强制转换
- application:didFinishLaunchingWithOptions:详解
iOS 程序启动时总会调用application:didFinishLaunchingWithOptions:,其中第二个参数launchOptions为NSDictionary类型的对象,里面存储有 ...
- iOS ZBarSDK的基本使用:扫描
1.首先使用Cocoapods导入库 ZBarSDK 2.敲代码: ViewController.h // // ViewController.h // erweima // // Created b ...