本文介绍了编写SQL存储过程时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞!CREATE PROCEDURE [dbo].[sp_empInfo]@empID int =null,@TesterName varchar(250)=nullasdeclare @strSql nvarchar(4000)SET@strSql='Declare users_cursor CURSOR FOR SELECT ID,TesterName FROM emp Where Status=1 'IF @empID IS NOT NULL AND LEN(@empID) > 0SET@strSql = @strSql +' AND ID='+CAST(@empID AS NVARCHAR(10))IF @TesterName IS NOT NULL AND LEN(@TesterName) > 0SET@strSql = @strSql +' AND TesterName='+@TesterNameexec sp_executesql @strSql open users_cursorfetch next from users_cursor into @empID, @TesterNamewhile @@FETCH_STATUS = 0 BEGIN---PROCESS fetch next from users_cursor into @empID, @TesterName END close users_cursordeallocate users_cursorwhen i pass TesterName as Nil I'm getting ErrorInvalid column name 'Nil' 我尝试了什么: 尝试追加N即SET @ strSql = N'Declare 但没有workWhat I have tried:Tried Appending N i.e. SET@strSql=N'Declarebut didn't work推荐答案 SET @strSql = @strSql +'AND TesterName ='+ @ TesterName 应该是 SET @strSql = @strSql +'和TesterName ='''+ @ TesterName +''''SET@strSql = @strSql +' AND TesterName='+@TesterNameshould beSET@strSql = @strSql +' AND TesterName='''+@TesterName + '''' 这篇关于编写SQL存储过程时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS!
05-22 15:44