SQL里面如何返回行信息
我用SELECT语句查出了需要的资料,但还差一列序号,按查出的资料第一条记录为一,第二条为二。请大家帮帮小弟!

解决方案 »

  1.   

    select *,identity(int,1,1) TID into #temp
    from tableName--此表可以是记录集。。
      

  2.   


    --可以借助临时表处理。create table #t(num int )insert #t select 20
    insert #t select 26
    insert #t select 45select * from #tselect identity(int,1,1) as id,*
    into #tp
    from #tselect * from #tpdrop table #t,#tp
      

  3.   

    考虑下面的方法:
    USE pubs
    SELECT seq_id = Count(*),
           au_a.au_id,
           au_a.au_lname,
           au_a.au_fname,
           au_a.phone,
           au_a.address,
           au_a.city,
           au_a.state,
           au_a.zip,
           au_a.contract
    FROM authors au_a,authors au_b
    WHERE au_a.au_id >= au_b.au_id  --一定要用主键
    GROUP BY au_a.au_id,
           au_a.au_lname,
           au_a.au_fname,
           au_a.phone,
           au_a.address,
           au_a.city,
           au_a.state,
           au_a.zip,
           au_a.contract建议你最好在前台程序中实现.
      

  4.   

    --假设表中有唯一字段ID,可以使用如下SQL:select (select count(*) from 表名 where ID <= A.ID) as 序号,*
    from 表名 A