本文介绍了为什么我得到goto错误..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我收到Goto错误,即使我已标记.. 消息133,等级15,状态1,行79 A GOTO语句引用了标签'ERROR_HANDLER',但标签尚未声明。 错误处理程序显示检查格式表,结果它工作正常但是goto是将错误抛给error_handler Nodups不应该打印和创建。 提前致谢。 我尝试了什么:I am getting Goto Error even i have labeled..Msg 133, Level 15, State 1, Line 79A GOTO statement references the label 'ERROR_HANDLER' but the label has not been declared.Error Handler is displaying check format table at the end it is working fine but as goto is throwing error to error_handler Nodups should not have been printed and created.Thanks in advance.What I have tried:-------- FONM --------ALTER PROCEDURE USP_FONM_16_FILES(@COMMAND NVARCHAR (MAX) ,@DBNAME NVARCHAR(MAX) ,@FORMAT_TABLE NVARCHAR (MAX) ,@FORMAT_NODUPS NVARCHAR (MAX)--,--@MAX_IDENTITY NVARCHAR (MAX))ASBEGINIF @COMMAND =N'HOMEOWNER'BEGINDECLARE @SRC_HM_DATA_TYPE NVARCHAR(MAX)SET @SRC_HM_DATA_TYPE=N''+CONCAT('BEGINIF EXISTS (SELECT [SRC_HM],DATA_TYPE FROM ',@DBNAME,'..',@FORMAT_TABLE,' WHERE [SRC_HM]=''1'' AND DATA_TYPE=''D'') PRINT ''SRC_HM=1 AND DATA_TYPE = D''ELSEGOTO ERROR_HANDLER;END')ENDBeginDECLARE @ERROR_HANDLER NVARCHAR(MAX)SET @ERROR_HANDLER=N''+CONCAT('ERROR_HANDLER:','Print ''check format table ''')EndBEGINDECLARE @REMOVE_NODUPS NVARCHAR (MAX)PRINT '-- REMOVE DUPLICATES -- 'SET @REMOVE_NODUPS=N''+CONCAT('IF OBJECT_ID (','''',@FORMAT_NODUPS,'''',',','''','U','''',') IS NOT NULL DROP TABLE ', @DBNAME,'..',@FORMAT_NODUPS,';WITH SAMPLECTEAS(SELECT A.*, ROW_NUMBER () OVER ( PARTITION BY FIRST_NAME, LAST_NAME, ADDRESS, ZIP ORDER BY FIRST_NAME ) AS RNUMFROM ', @DBNAME,'..',@FORMAT_TABLE,' A)SELECT * INTO ', @DBNAME,'..',@FORMAT_NODUPS,'FROM SAMPLECTE WHERE RNUM=1')ENDPRINT @SRC_HM_DATA_TYPEEXEC (@SRC_HM_DATA_TYPE)PRINT @REMOVE_NODUPSEXEC (@REMOVE_NODUPS)PRINT @ERROR_HANDLEREXEC (@ERROR_HANDLER)END-- Output ---- REMOVE DUPLICATES --BEGINIF EXISTS (SELECT [SRC_HM],DATA_TYPE FROM prac..test_format1 WHERE [SRC_HM]='1' AND DATA_TYPE='D') PRINT 'SRC_HM=1 AND DATA_TYPE = D'ELSEGOTO ERROR_HANDLER;ENDMsg 133, Level 15, State 1, Line 77A GOTO statement references the label 'ERROR_HANDLER' but the label has not been declared.IF OBJECT_ID ('Test_format_nodups','U') IS NOT NULL DROP TABLE prac..Test_format_nodups;WITH SAMPLECTEAS(SELECT A.*, ROW_NUMBER () OVER ( PARTITION BY FIRST_NAME, LAST_NAME, ADDRESS, ZIP ORDER BY FIRST_NAME ) AS RNUMFROM prac..test_format1 A)SELECT * INTO prac..Test_format_nodupsFROM SAMPLECTE WHERE RNUM=1(5 rows affected)ERROR_HANDLER:Print 'check format table 'check format table--its working推荐答案我没有看到你的回复,因为你没有使用回复,否则我会早点回复。 将所有SQL连接成一个Exec ...I didn't see your reply as you didn't use "Reply" otherwise I would have answered this sooner.Concatenate all of the SQL into a single Exec...DECLARE @FinalSQL NVARCHAR(MAX)SET @FinalSQL = @SRC_HM_DATA_TYPE + ' ' + @REMOVE_NODUPS + ' ' + @ERROR_HANDLEREXEC (@FinalSQL)空格可能不会是必要但不做任何伤害The spaces might not be necessary but don't do any harm 这篇关于为什么我得到goto错误..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 01:42