select id=identity(int,1,1),* into #t from tableselect * from #t

解决方案 »

  1.   

    能不能用一条语句实现涅?比如,我就想要where a=22前面的2
      

  2.   

    lsxaa(小刀) 这样的identity方法,会生成一个新表,如果用户只有读取,没有创建表的权限,会不会出错?
      

  3.   

    select left(a,1),*  from table
      

  4.   

    55555.....我举的这个例子中的数据不太好,太有规律了。我不是要取得a字段的第一个字符。我是要取得它前面的那个,在SQL里显示为按钮的那个字符。
      

  5.   

    抄别人的:
    select id=(select count(*) from 表 where 主键<=a.主键),* from 表 a
      

  6.   

    --抄的好啊。兄弟。虽然感觉不是很完美,我整理一下。
    --------------------------------------------
    --测试数据
    select a=111 into # union all
    select a=333 union all
    select a=222 union all
    select a=444  select * from #
    --测试数据
    select myid=(select count(*) from # where a<=sex.a ) from # sex where a=222
    --删除测试
    drop table #