我没有sql
我觉得游标这样动态声明是没有用的
exec('select top 1 * into tmpRecord from '+@strTableName+' where '+@strWhere)

解决方案 »

  1.   

    exec('declare  curFetchRecordField cursor for select name,xtype,length from syscolumns where '+@tableID)     open  curFetchRecordField
    我觉得游标这样动态声明是没有用的
      

  2.   

    TO:aierong(皑婀瑢-数据库XML.NET联盟会局长)
        謝謝提醒,我試試.
      

  3.   

    TO:aierong(皑婀瑢-数据库XML.NET联盟会局长)    游标这样动态声明是用的.
      

  4.   

    復制表結構至臨時表中,select top 0 * into 就行了。     if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tmpRecord]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
         drop table [dbo].[tmpRecord]      exec('select top 0 * into tmpRecord from '+@strTableName+' where '+@strWhere)
          
    其它的还没看明白。
      

  5.   

    查询分页,这么累不行。用游标,更不行
    每个要查询的表加上主键或,INDETIYI列
    比如ID为IDENTITY列
    取第201到300的记录:select top 100 * from table where id not in (select top 200 id from table)
      

  6.   

    exec(@a)在@a中的命令,工作在另外一个工作区(会话),根本不能访问它外边变量,也不能传递出任何变量值!
      

  7.   

    你可以在@a中创建一个临时表,在执行exec之后,这个临时表并不存在。
      

  8.   

    看看这个帖子,也许有帮助.http://expert.csdn.net/Expert/topic/2495/2495874.xml?temp=.5654718