请教一个MSSQL储存过程编写
比如
mssql数据库
table表的内容
id	a	b	uid
1	123	xxx	1
2	321	aaa	1
3	456	asd	2
4	456	ssss	2
5	3251	aaasss	3
6	2323	ssssaa	3
7	3211	bbbb	1
8	3332	asdd	1
9	541545	gggg	2
int $num=select count(distinct uid) from table;
select distinct uid from table;
把uid的内存保存成一个数组arr
arr[0]=1
arr[1]=2
arr[2]=3
for ($i=0;$i<$num;$i++1){
update table set a=(select top 1 a from table where uid=arr[i]),b=(select top 1 b from table where uid=arr[i]) where uid=arr[i];
}
执行后变成
id	a	b	uid
1	123	xxx	1
2	123	xxx	1
3	456	asd	2
4	456	asd	2
5	3251	aaasss	3
6	3251	aaasss	3
7	123	xxx	1
8	123	xxx	1
9	456	asd	2
请问详细代码该如何写?
------解决方案--------------------
UPDATE Table SET a =tp.a , b = tp.b
FROM Table t 
CROSS APPLY (SELECT TOP 1 a, b FROM Table WHERE uid = t.uid ORDER BY id) tp