1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 关于sql where id in 转换成数据类型 int 时失败

关于sql where id in 转换成数据类型 int 时失败

时间:2019-12-05 00:36:05

相关推荐

关于sql where id in 转换成数据类型 int 时失败

数据库|mysql教程

sql 转换int,sql varchar转换int,sql

数据库-mysql教程

深圳旅行社源码,vscode 代码片段插件,ubuntu ssh p,访问tomcat页面空白,sqlite一条数据多大,pyautogui 爬虫,php正则匹配div,辽宁seo推广哪家便宜,企业网站 自适应,博客园模板lzw

有执行sql条件语句where id in(@参数)的时候,如果处理不当,就会出现问题:

asp网站源码恶搞,vscode怎么多行光标,ubuntu 远程下载,tomcat 修改窗口,sqlite3 表达式,爬虫晋江小说代码运行不出来,php 二值化,晋城seo优化询问报价,oecms(php企业网站管理系统),app 登录模板lzw

网页小游戏站源码下载,ubuntu查看更新源,在工程中添加tomcat,ocr 爬虫技术,php 建站cms,云阳专业性seo推广代运营lzw

有执行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 时失败。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。