日期:2014-05-17  浏览次数:20718 次

哪位大侠神仙围观一下,看看什么原因啊,50分啊~~~~~~~~~~~~~~~
alter proc P_TCC_INF_UseCaseQuery  
as  
begin  
declare @opename varchar(200)
declare @tablename varchar(200)
declare @module_displayname varchar(200)
declare @projectidField varchar(200)
declare @keyField varchar(100)
declare @registerdatefield varchar(200)
declare @registernameField varchar(100)
declare @statusfield varchar(1000)
declare @sql varchar(8000)
declare @sid bigint
declare @cur cursor
 
create table #t(
TOpeName varchar(200),TtableName varchar(200),
TModule_DisplayName varchar(200),TprojectidField varchar(200),
TkeyField varchar(100),Tregisterdatefield varchar(200),
TregisternameField varchar(100),Tstaus varchar(1000)
)

set @cur = cursor
for
select OpeName,tableName,Module_DisplayName,projectidField,keyField,registerdatefield,
registernameField,statusfield from TCC_V_INF_UseCaseQuery
 
open @cur  
fetch next from @cur into @OpeName,@tableName,@Module_DisplayName,
@projectidField,@keyField,@registerdatefield,@registernameField,@statusfield  
while @@FETCH_STATUS=0  
begin  
set @sql = 'insert into #t (TprojectidField,TkeyField,Tregisterdatefield,TregisternameField,Tstaus) 
select '+@projectidField+','+@keyField+',
'+@registerdatefield+','+@registernameField+','+@statusfield+' from ' +@tablename+ ' '
exec (@sql)
print(@sql)
fetch next from @cur into @OpeName,@tableName,@Module_DisplayName,@projectidField,
@keyField,@registerdatefield,@registernameField,@statusfield
end 
close @cur  
deallocate @cur 
select * from #t
drop table #t
end
 


老是报错:消息 102,级别 15,状态 1,第 3 行 ',' 附近有语法错误。

分析一下什么原因啊,不甚感激


------解决方案--------------------
我这边编译是通过的 不过没看你的逻辑。
------解决方案--------------------
我估计还是exec (@sql) @sql里面的拼接有问题,你运行一下,把@sql的值复制出来看看。
------解决方案--------------------
我仔细看了下,也在Management Studio 编译通过,没有报错信息
------解决方案--------------------
SQL code

set @sql = 'insert into #t (TprojectidField,TkeyField,Tregisterdatefield,TregisternameField,Tstaus)  
select '+@projectidField+','+@keyField+',
'+@registerdatefield+','+@registernameField+','+@statusfield+' from ' +@tablename+ ' '
exec (@sql)