SQL2005,我想写一SQL语句,在查询分析器里:declare @NationCode varchar(200)
set @NationCode = '132,136'--print @NationCodeSelect * From t_area where NationCode in (@NationCode)这样结果为空
当set @NationCode = '132'时结果就有三条,为什么?
set @NationCode = '132,136'--print @NationCodeSelect * From t_area where NationCode in (@NationCode)这样结果为空
当set @NationCode = '132'时结果就有三条,为什么?
set @NationCode = '132,136' EXEC('Select * From t_area where NationCode in ('+@NationCode+')')
set @s='''A'',''B'''
exec('select * from tb where Mame in ('+@s+')')用动态的
declare @NationCode varchar(200)
declare @sql varchar(8000)
set @NationCode = '132,136'
select @sql = 'Select * From t_area where NationCode in ('+@NationCode+')'EXEC(@sql)
set @NationCode = '132,136'
set @NationCode =@NationCode+',' --注意多加个逗号!!Select * From t_area where CHARINDEX( NationCode,@NationCode)>0 用charindex函数
这样应该可以
并注意前后辍加,比如
where charindex(','+nationcode+',',','+@nationcode+',')>0