DECLARE m_info CURSOR FOR
SELECT @Colname FROM database_table WHERE id=@id
OPEN m_info
fetch next FROM m_info into @Value
CLOSE m_info
DEALLOCATE m_info还有在游标中也是一样
SELECT @Colname FROM database_table WHERE id=@id
OPEN m_info
fetch next FROM m_info into @Value
CLOSE m_info
DEALLOCATE m_info还有在游标中也是一样
declare @col nchar(255)
set @col='户名'
exec('select '+@col+' from database_table')
set @s='DECLARE m_info CURSOR FOR
SELECT '+@Colname+' FROM database_table WHERE id='''+cast(@id as varchar)+''''
exec(@s)
OPEN m_info
fetch next FROM m_info into @Value
CLOSE m_info
DEALLOCATE m_info
declare @col nchar(255)
set @col='户名'
exec('select '+@col+' from database_table')
select @col from database_table
其实就相当于select '户名' from database_table
查询后的结果当然全是户名其实你要的是:select 户名 from database_tableset @str='select' +@col +' from database_table'
print @str
exec(@str)
declare @col nchar(255)
set @col='户名'
select @col=戶名字段 from database_table