delare dnxh int
 set @dnxhselect f_name,@dnxh=@dnxh+1 as f_dnxh from tbda;我的意思是让变量每次加1如下结果:
A,1
B,2
C,3
现在出现问题是"向变量赋值的 SELECT 语句不能与数据检索操作结合使用。" 而且还出现as错误,哪位知道怎么做呀,,,,急~~~~在线等啊。

解决方案 »

  1.   

    语法上不支持这样的功能,在SQL Server 2000中可以用临时表。select f_name,f_dnxh=identity(int,1,1) into # from tbdaselect * from #drop table #
      

  2.   

    create table T(col1 varchar(10))
    insert T select 'A'
    insert T select 'B'
    insert T select 'C'select col1, col2=(select count(*) from T where col1<=A.col1) from T as A--result
    col1       col2        
    ---------- ----------- 
    A          1
    B          2
    C          3(3 row(s) affected)