select top 6 Voter from tblVOTEVoteRecord a  left join  
tblVOTEActivityInfo b on a.ActivityID=b.ActivityID
where a.ActivityID='43bf7430dbae435ca0c1f4856eb8cefa' order by newid()查询出来的结果如下:
Voter
1111
2222
3333
4444
5555
6666我该如何把查询到的这些值插入到另一个表中,循环遍历这个查询的结果,但是该如何写,求大虾门指点下,我新手。

解决方案 »

  1.   

    1.先放入临时表
    2.从临时表插入正式表
    3.再遍历临时表
    select top 6 Voter into #temp from tblVOTEVoteRecord a left join   
    tblVOTEActivityInfo b on a.ActivityID=b.ActivityID
    where a.ActivityID='43bf7430dbae435ca0c1f4856eb8cefa' order by newid()insert yourtable select * from #tempselect * from #temp
      

  2.   

    insert into xxx select xxxx
      

  3.   

    我是说在SQL语句写好了,在前台如何遍历到查询出来的表,就是
     DataTable dt = DrawingRules.GetPhoneNumber(n, activityID);
      for (int t = 1; t <= dt.Rows.Count; t++)
                        {
                            string phoneNumber = dt.Rows[t][0].ToString();
                            bResult = DrawingRules.InsertWinnerList(Common.NewGuid, this.DrawingID, activityID, id.Text, phoneNumber);
                        }
    就是这样的,但是我这个有错,
      

  4.   

    1、 for (int t = 1; t <= dt.Rows.Count; t++)
    改成 for (int t = 1; t < dt.Rows.Count; t++)2、如果还错的话,就要看DrawingRules.InsertWinnerList()这个方法的问题了。
      

  5.   

    索引是从0开始的
    count=9的时候索引是0--8