当前位置: 代码迷 >> Sql Server >> 字符串转INT型解决方案
  详细解决方案

字符串转INT型解决方案

热度:84   发布时间:2016-04-27 13:41:17.0
字符串转INT型
declare @str varchar(200)
set @str = '3,314,311,312,313,316,325,2223,2224,2225,327,319,321,2219,2221,2226'
select 2544, lxbh,20120327 from t_table where lxbh in (@thlxs)

因为t_table 中的lxbh是int型,[email protected]

------解决方案--------------------
declare @str varchar(200)
set @str = '3,314,311,312,313,316,325,2223,2224,2225,327,319,321,2219,2221,2226'
exec('select 2544, lxbh,20120327 from t_table where lxbh in ([email protected]+''')')[code=SQL][/code]
------解决方案--------------------
探讨
declare @str varchar(200)
set @str = '3,314,311,312,313,316,325,2223,2224,2225,327,319,321,2219,2221,2226'
select 2544, lxbh,20120327 from t_table where lxbh in (@thlxs)

因为t_table 中的lxbh是int型,所以……

------解决方案--------------------
declare @str varchar(200)
set @str = '3,314,311,312,313,316,325,2223,2224,2225,327,319,321,2219,2221,2226'
select 2544, lxbh,20120327 from t_table where ',[email protected]+',' like '%,'+ltrim(lxbh)+',%'

------解决方案--------------------
用动态或用patindex/charindex/like
SQL code
declare @str varchar(200)set @str = '3,314,311,312,313,316,325,2223,2224,2225,327,319,321,2219,2221,2226'select 2544, lxbh,20120327 from t_table where charindex('%,'+rtrim(lxbh)+',%',',[email protected]+',')>0
  相关解决方案