CNN.Execute sql
    sql = "select @@identity as qq"
    Set rs_temp = CNN.Execute(sql)
    temp_id = rs_temp("qq").Value

解决方案 »

  1.   

    @@identity 中双@@表示后面的变量为全局变量,select @@identity as qq 中as qq 表示qq作为identity的别名(即另外的名称)
    Set rs_temp = CNN.Execute(sql)
    表示rs_temp 是记录集合 CNN.Execute(sql) 表示执行上面的sql语句产生结果赋值给rs_temp
    temp_id = rs_temp("qq").Value表示变量temp_id 的值为记录集合rs_temp的第一条记录中字段identity或者说是QQ的值
      

  2.   

    This is rather simple:    sql = "select @@identity as qq"
    sql: a String that holds an SQL statement of "select @@identity as qq".  I don't think the SQL statement makes much sense.  However, basically it renames @@identity to qq.    Set rs_temp = CNN.Execute(sql)
    Execute the SQL statement defined in sql by do an Execute on CNN.  Note CNN here is the Connection object.  This will return a ResultSet object, which is passed to variable rs_temp.    temp_id = rs_temp("qq").Value
    Now we want to fetch the value of column "@@identity".  Note "@@identity" is the same as "qq" or is exposed as "qq" in the first line.  The feteched value is stored in temp_id variable.Hope this helps!
      

  3.   

    謝謝各位逐句的解釋﹐我想知道的是它們放在一起有什么作用。
    例如﹕sql = "select @@identity as qq"
        Set rs_temp = CNN.Execute(sql)
        rs_temp得到的是重哪里反回的记录集再次感謝各位的關注
      

  4.   

    CNN.Execute sql '这一句是多余的
        sql = "select @@identity as qq" '设置SQL语句,取得字增值主键的值,放入别名为QQ的字段里
        Set rs_temp = CNN.Execute(sql) '执行SQL语句,CNN是ADO的数据链接,将返回的结果赋值给记录集
        temp_id = rs_temp("qq").Value '从记录集中取出数据,放入变量
      

  5.   

    I have searched the key .After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY contains the last identity value generated by the statement. If the statement did not affect any tables with identity columns, @@IDENTITY returns NULL. If multiple rows are inserted, generating multiple identity values, @@IDENTITY returns the last identity value generated. If the statement fires one or more triggers that perform inserts that generate identity values, calling @@IDENTITY immediately after the statement returns the last identity value generated by the triggers. The @@IDENTITY value does not revert to a previous setting if the INSERT or SELECT INTO statement or bulk copy fails, or if the transaction is rolled back.@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions in that they return the last value inserted into the IDENTITY column of a table. @@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.Examples
    use pubs
    INSERT INTO jobs (job_desc,min_lvl,max_lvl)
    VALUES ('Accountant',12,125)
    SELECT @@IDENTITY AS 'Identity'result
    --------------------
        Identity
    1   15
      

  6.   

    我這里沒有中文的SQL Server ,有的可以再help中找一下@@identity,回有中文help