表A为 ID NAME COUNTS
表B为 ID .......(几十列)
需要根据表A的ID去表B随机取数据取的数据条为表A里的COUNTS字段数,并把结果并在一起。如何实现?
------解决方案--------------------
declare @id int,@counts int
select @id=[输入值]
select @counts=COUNTS from 表A where ID=@id
select top (@counts) *
from b
where id=@id
order by newid()