sql server - get the string after check 2nd comma separated string not in 1st comma separated string -


i have table named btsqmtask , has 2 tasks in it. each task have column completedid, comma separated column. need return completedid of task not in 2nd task(remember both comma separated values). please me find answer. stuck on this

taskid       taskname              completedid  1            upload signed sow     1,2,3,5,4,9 2            confirm payment       1,5 

in this, must compare completedid of both tasks , return result must '2,3,4,9'

- output

completedid  2,3,4,9 

this solution not require change schema.

so use either of 2 solutions generate function return list delimited string: tolist() delimited string. like:

/* test data */ create table dbo.foo ( id integer, idlist varchar(100) ) insert foo  select 1, '1,2,3,4,5' union select 2, '1,5' /* end test data */  declare @arr varchar(100) set @arr = '' select @arr = @arr + a.arrvalue + ','   (         select count(x.arrvalue) cnt,                 x.arrvalue           dbo.foo f          cross apply dbo.fnarray(f.idlist, ',') x          group x.arrvalue          having count(x.arrvalue) = 1     ) set @arr = left(@arr, len(@arr) - 1) print @arr 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -