[sqlserver] 按逗号分割字符串

declare @fibi_ID_STR varchar(8000)
set @fibi_ID_STR='255,472,473,491,494,495,497,500,502,503,506'

declare @fi_ID_STR varchar(8000)
SET @fi_ID_STR=''

DECLARE @fibi_ID_SQL varchar(8000)
		set @fibi_ID_SQL='select DEL_BAS_ID='''+ replace(@fibi_ID_STR,',',''' union all select ''')+''''
	DECLARE @fibi_ID int
	exec('DECLARE fibi_ID_CURSOR CURSOR FOR '+ @fibi_ID_SQL)

open  fibi_ID_CURSOR fetch next from fibi_ID_CURSOR into @fibi_ID
while  (@@fetch_status=0)  
	begin  
	    print @fibi_ID
	    fetch next from fibi_ID_CURSOR into @fibi_ID
	end
close fibi_ID_CURSOR
deallocate fibi_ID_CURSOR



你可能感兴趣的:([sqlserver] 按逗号分割字符串)