sql - Stored procedure doesn't compile -



sql - Stored procedure doesn't compile -

i wrote stored procedure , know individual queries in there work. implemented standardized template across company used exception flow.

use [dev_serv] go set ansi_nulls on go set quoted_identifier on go create procedure [sch].[usp_tmsetstat] @stat varchar(50), @statdesc varchar(50), @parent_stat varchar(50), @status smallint begin set nocount on declare @parent hierarchyid declare @sibling hierarchyid declare @oldparent hierarchyid declare @newparent hierarchyid declare @currentpos hierarchyid declare @statusinactivekey smallint begin seek if exists (select 1 [sch].[stat_path] [stat_code] = @stat) begin set @oldparent = (select [stat_path] tmppath [sch].[stat] stat_code = (select s.parent_stat_code [sch].[stat_path] s s.stat_code = @stat)) set @newparent = (select [stat_path] tmppath [sch].[stat] t.stat_code = @parent_stat); set @currentpos = (select [stat_path] tmppath [sch].[stat] t.stat_code = @stat); update [sch].[stat] set stat_path = @currentpos.getreparentedvalue(@oldparent, @newparent) stat_key = @stat go end else begin set @parent = (select [stat_path] tmppath [sch].[stat] t t.stat_code = @parent_stat) set @sibling = (select top 1 [stat_path] [sch].[stat] t parent_stat_code = @parent_stat order t.stat_key desc) set @statusinactivekey = [dbo].[udf_getstatuskey]('active') insert [sch].[stat] ([stat_code], [stat_desc], [stat_path], [point_type], [status_key]) values (@stat, @statdesc, @parent.getdescendant(@sibling, null), 't', @statusinactivekey) go end end seek begin grab end grab end

however these annoying errors like;

msg 102, level 15, state 1, procedure usp_tmsetstat, line 60 wrong syntax near '@stat'. msg 156, level 15, state 1, line 3 wrong syntax near keyword 'else'. msg 137, level 15, state 2, line 7 must declare scalar variable "@parent_stat". msg 137, level 15, state 2, line 11 must declare scalar variable "@parent_stat". msg 137, level 15, state 1, line 14 must declare scalar variable "@statusinactivekey". msg 137, level 15, state 2, line 24 must declare scalar variable "@stat". msg 156, level 15, state 1, line 3 wrong syntax near keyword 'end'. msg 137, level 15, state 2, line 6 must declare scalar variable "@stat". msg 137, level 15, state 2, line 7 must declare scalar variable "@errtemplate". msg 137, level 15, state 2, line 8 must declare scalar variable "@errtemplate". msg 137, level 15, state 2, line 9 must declare scalar variable "@errtemplate". msg 137, level 15, state 2, line 10 must declare scalar variable "@errtemplate". msg 137, level 15, state 2, line 11 must declare scalar variable "@errtemplate". msg 137, level 15, state 1, line 12 must declare scalar variable "@errprocedure". msg 137, level 15, state 1, line 13 must declare scalar variable "@errnumber". msg 137, level 15, state 1, line 14 must declare scalar variable "@errline". msg 137, level 15, state 1, line 15 must declare scalar variable "@errseverity". msg 137, level 15, state 1, line 16 must declare scalar variable "@errstate". msg 137, level 15, state 2, line 18 must declare scalar variable "@errprocedure". msg 137, level 15, state 2, line 20 must declare scalar variable "@errtemplate". msg 137, level 15, state 2, line 25 must declare scalar variable "@retval".

i pasted whole stored proc in there, know what's wrong? supposed declare something?

you have go statement in middle of stored proc. remove it, , should good.

sql sql-server sql-server-2008 stored-procedures

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -