谁知道怎样用SQL语句select:
比如select出来的是
a b c 
aa ee cc
我要在前面加个序号,变成
1 a b c
2 aa ee cc 
序号1,2...n不在数据库里,是根据select出来的东西自动添加的.

解决方案 »

  1.   

    declare @t table (id varchar(18))
    insert into @t select '6227228001011011' 
    union all select '622722199001011011'
    union all select '622722198801011011'
    union all select '622722890101101'
    --
    select siteID=identity(int,1,1),id into # from @tselect * from #drop table #
      

  2.   

    identity(int,1,1)是用来插入表的吧,我只要显示表
      

  3.   

    simonhehe() 的方法已经很清楚,照你说的只显示在Sq server2000里是不能实现的
    在2005里面有个row_number()函数可以实现你要的功能!
      

  4.   

    declare @t table (id varchar(18))
    insert into @t select '6227228001011011' 
    union all select '622722199001011011'
    union all select '622722198801011011'
    union all select '622722890101101'
    --
    select siteID=identity(int,1,1),id into # from @t
    ---------------------------------------------------
    注意这个地方虽然是插入,但是是插入的一个临时表select * from #
    --------------------------------------------------这里显示临时表内容,drop table #
    --------------------------
    这里把临时表又删掉了所以,其实显示的时候你看到的就是加了序号的结果而已。
      

  5.   

    直接使用identity()属性就可以了
    参看onlinebook