1:查询的原型
select * from fype in( 11,12 )
ftyep 表示单据类型 int 类型.但是现在 fype in ()里面的内容是不确定的@declae
@ftype varchar(255)
set @ftype='11,12 'select * from fype in(@ftype ) 的查询结果 跟 select * from fype in( 11,12 ) 是不一样的.
select * from fype in(@ftype ) 这样查询是一条记录么有
select * from fype in( 11,12 ) 是有记录的.
请问SQL in 里面的变量查询 不要用 动态的SQL语句
select * from fype in( 11,12 )
ftyep 表示单据类型 int 类型.但是现在 fype in ()里面的内容是不确定的@declae
@ftype varchar(255)
set @ftype='11,12 'select * from fype in(@ftype ) 的查询结果 跟 select * from fype in( 11,12 ) 是不一样的.
select * from fype in(@ftype ) 这样查询是一条记录么有
select * from fype in( 11,12 ) 是有记录的.
请问SQL in 里面的变量查询 不要用 动态的SQL语句
set @list = '11,12'exec ('select * from fype in('+@list+')')
不好意思 我写错了 忘写 from 表了
select * from tb where fype in (212,213)
想用变量替代 in 里面的内容
@ftype varchar(255)
set @ftype='11,12 '
select * from tb where fype in (@ftype)但是不想用 动态SQL 语句
declare @ftype varchar(255)
set @ftype='11,12'
select * from tb where charindex(','+ltrim(fype)+',',','+@ftype+',')>0
declare @b int
set @a =11
set @b = 12
select * from table where fype in (@a,@b)如果in中的参数有多个,那就比较绕了
那就要多个变量declare @1 bigint, @2 bigint, @3 bigint, @4 bigintselect top 1 @1 = id from sysobjects order by id
select top 1 @2 = id from sysobjects order by id descselect * from sysobjects where id in (@1,@2,@3,@4)
看看charindex(参数1,参数2)函数的用法,就是返回参数1在参数2中的起始位置
这个位置大于0,说明参数1在参数2中是存在的前后加逗号, 是为了避免找1的时候却把11,12,111等也找出来