--应该用:exec('declare XKB_cursor cursor for 
  select  top  '+cast(@jsrl as varchar)+' 考试地点,考试时间  from 学生选课表 where 
教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号')

解决方案 »

  1.   

    declare XKB_cursor cursor for 
      select  top  ''+cast(@jsrl as varchar(10))+''  考试地点,考试时间  from 学生选课表 where 
    教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号
      

  2.   

    必须全部是字符型。http://expert.csdn.net/Expert/topic/2364/2364046.xml?temp=.829693
    [交流]动态SQL语句
      

  3.   

    --上面的也错了,应该是:declare @s varchar(8000)
    set @s='declare XKB_cursor cursor for 
      select  top  '+cast(@jsrl as varchar)+' 考试地点,考试时间  from 学生选课表 where 
    教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号'
    exec(@s)
      

  4.   

    declare @sql nvarchar(4000)
    declare XKB_cursor cursor for 
      select  top  ''+cast(@jsrl as varchar(10))+''  考试地点,考试时间  from 学生选课表 where 
    教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号Exec(@sql)
      

  5.   

    declare @sql nvarchar(4000)
    set @sql = '
    declare XKB_cursor cursor for 
      select  top  ''+cast(@jsrl as varchar(10))+''  考试地点,考试时间  from 学生选课表 where 
    教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号'Exec(@sql)
      

  6.   

    declare @s varchar(4000)
    set @s='declare XKB_cursor cursor for 
    select  top  '+cast(@jsrl as varchar)+' 考试地点,考试时间  from 学生选课表 where 
    教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号'
    exec(@s)
      

  7.   

    定义游标也可以这样写吗?
    declare @sql nvarchar(4000)
    set @sql = '
    declare XKB_cursor cursor for 
      select  top  ''+cast(@jsrl as varchar(10))+''  考试地点,考试时间  from 学生选课表 where 
    教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号'Exec(@sql)
      

  8.   

    declare @sql varchar(8000)
    set @sql = 'declare XKB_cursor cursor for 
      select  top  '+ @jsrl+ '  考试地点,考试时间  from 学生选课表 where 
    教学班号=''' + @jxbh + ''' and  学年学期= '''+ @xnxq + ''' and  考试地点 is null order by 学号'exec (@sql)
    open XKB_cursor
    ...
      

  9.   

    到底是:
    declare @s varchar(4000)
    set @s='declare XKB_cursor cursor for 
    select  top  '+cast(@jsrl as varchar)+' 考试地点,考试时间  from 学生选课表 where 
    教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号'
    exec(@s)
    还是:
    declare @sql nvarchar(4000)
    set @sql = '
    declare XKB_cursor cursor for 
      select  top  ''+cast(@jsrl as varchar(10))+''  考试地点,考试时间  from 学生选课表 where 
    教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号'Exec(@sql)
      

  10.   

    declare @a varchar(8000)
    set @a='declare XKB_cursor cursor for select  top  '+@jsrl+'  考试地点,考试时间  from 学生选课表 where 教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号'exec(@a)
      

  11.   

    declare @a varchar(8000)
    set @a='declare XKB_cursor cursor for select  top  '+cast(@jsrl as varchar(10))+'  考试地点,考试时间  from 学生选课表 where 教学班号='''+@jxbh+''' and  学年学期='''+@xnxq+''' and  考试地点 is null order by 学号'exec(@a)