in的用法

--三個SQL結果相同
select DETL_BAT_FIELD from rpt_head 
where RP_TEMPLET in (3,4) and isnull(DETL_BAT_FIELD,'')<>'' and COM_NO='00'

declare @rp_templet varchar(10)
set @rp_templet='3,4'
select DETL_BAT_FIELD from rpt_head 
where CharIndex(','+RP_TEMPLET+',',','+@rp_templet+',')>0   and isnull(DETL_BAT_FIELD,'')<>'' and COM_NO='00'


set @rp_templet='''3'',''4'''
select DETL_BAT_FIELD from rpt_head 
where CharIndex(','''+RP_TEMPLET+''',' , ','+@rp_templet+',')>0   and isnull(DETL_BAT_FIELD,'')<>'' and COM_NO='00'

你可能感兴趣的:(sql)