CREATE PROCEDURE selectsum
(
@sumpoint int output,
@questionType nvarchar(100),
@paperTitle nvarchar(100)
)
AS
declare @S nvarchar(4000)
exec(' if exeits(select * from [ ' +@paperTitle+ ' ] where questionType= ''' +@questionType+ '')
BEGIN
set @S=N'select @sumpoint=sum(分数) from ' +@questionType+ ' where 题号 in (select questionID from ' +@paperTitle+ ' where questionType= ''' +@questionType+ ''' ) '
exec sp_executesql @S,N'@sumpoint int output',@sumpoint output select @sumpoint
end
exec(' if no exeits(select * from [ ' +@paperTitle+ ' ] where questionType= ''' +@questionType+ '')
set @sumpoint=0
return @sumpoint
GO
错误:在关键字 'select' 附近有语法错误。字符串 '单选题' 之前有未闭合的引号。第 1 行: '单选题' 附近有语法错误。第 1 行: 'exeits' 附近有语法错误。
(
@sumpoint int output,
@questionType nvarchar(100),
@paperTitle nvarchar(100)
)
AS
declare @S nvarchar(4000)
exec(' if exeits(select * from [ ' +@paperTitle+ ' ] where questionType= ''' +@questionType+ '')
BEGIN
set @S=N'select @sumpoint=sum(分数) from ' +@questionType+ ' where 题号 in (select questionID from ' +@paperTitle+ ' where questionType= ''' +@questionType+ ''' ) '
exec sp_executesql @S,N'@sumpoint int output',@sumpoint output select @sumpoint
end
exec(' if no exeits(select * from [ ' +@paperTitle+ ' ] where questionType= ''' +@questionType+ '')
set @sumpoint=0
return @sumpoint
GO
错误:在关键字 'select' 附近有语法错误。字符串 '单选题' 之前有未闭合的引号。第 1 行: '单选题' 附近有语法错误。第 1 行: 'exeits' 附近有语法错误。
(
@sumpoint int output,
@questionType nvarchar(100),
@paperTitle nvarchar(100)
)
AS
declare @S nvarchar(4000)
set @S=N'if exists(select * from [ ' +@paperTitle+ ' ] where questionType= ''' +@questionType+ ''')
select @sumpoint=sum(分数) from [' +@questionType+ '] where 题号 in (select questionID from [' +@paperTitle+ '] where questionType= ''' +@questionType+ ''' )
else
set @sumpoint=0'
exec sp_executesql @S,N'@sumpoint int output',@sumpoint output
GO--这样试试