--应该用:exec('declare XKB_cursor cursor for select top '+cast(@jsrl as varchar)+' 考试地点,考试时间 from 学生选课表 where 教学班号='''+@jxbh+''' and 学年学期='''+@xnxq+''' and 考试地点 is null order by 学号')
declare XKB_cursor cursor for select top ''+cast(@jsrl as varchar(10))+'' 考试地点,考试时间 from 学生选课表 where 教学班号='''+@jxbh+''' and 学年学期='''+@xnxq+''' and 考试地点 is null order by 学号
--上面的也错了,应该是: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)
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)
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)
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)
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 ...
到底是: 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)
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)
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)
select top ''+cast(@jsrl as varchar(10))+'' 考试地点,考试时间 from 学生选课表 where
教学班号='''+@jxbh+''' and 学年学期='''+@xnxq+''' and 考试地点 is null order by 学号
[交流]动态SQL语句
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 XKB_cursor cursor for
select top ''+cast(@jsrl as varchar(10))+'' 考试地点,考试时间 from 学生选课表 where
教学班号='''+@jxbh+''' and 学年学期='''+@xnxq+''' and 考试地点 is null order by 学号Exec(@sql)
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)
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)
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
...
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)
set @a='declare XKB_cursor cursor for select top '+@jsrl+' 考试地点,考试时间 from 学生选课表 where 教学班号='''+@jxbh+''' and 学年学期='''+@xnxq+''' and 考试地点 is null order by 学号'exec(@a)
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)