sql - Cross Join with Filter? -
i need make sp distribute students sections procedure take 2 string parameters stuid , secid
in case i've send '1,2,3,4,5' stuid , 'a,b' secid i'm using spliting function return tables
tb1 | tb2 1 | 2 | b 3 | 4 | 5 |
how can following result
1 2 b 3 4 b 5 ....
i've tried via cross join did not show result want
select us.vitem userid,se.vitem section split(@puserid,',') cross join split(@psectionid,',') se
cross join
isn't meant work that.
this give results want, it's bodge.
select t1.vitem, t2.vitem ( select *, row_number() on (order vitem) r ) t1 inner join ( select *, row_number() on (order vitem desc) -1 r se ) t2 on t2.r = t1.r % (select count(*) se) order t1.vitem
Comments
Post a Comment