|
Question : Error in Stored Proceedure Syntax
|
|
I had a developer write a store proceedure a while back and I needed to add some fields to sync and using the format I edited the SP, but get an error "Invlaid column name PARTPROT I know 100% sure that the reson is that I have ONE field in my parcels table called PARTIALPROT and my master table is called PARTPROT I don't understand the code to fine out what line I need to change that it is looking at the Parcels table. Here is the SP... can anyone give me a copy paste fix ?
USE [ASSESSMENTS] GO /****** Object: StoredProcedure [dbo].[PROC_MASTERSYNC] Script Date: 02/17/2010 09:28:13 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO
ALTER procedure [dbo].[PROC_MASTERSYNC] as begin
set nocount on
-- Get data from table ParcelMaster for analysing declare @cur_Master as cursor set @cur_Master = cursor fast_forward for select PID, BLDGINC, BLDGINCCHG, BLDGHEIGHT, BLDGHEIGHTCHG, WETPERCENT, WETPERCENTCHG, RETDBASN, RETDBASNCHG, EXEMPT, EXEMPTCHG, MULTIPLEBLDG, MULTIPLEBLDGCHG, BENEFIT, BENEFITCHG, PARTPROT, PARTPROTCHG from ParcelMaster declare @PID as nvarchar(50), @BLDGINC as int, @BLDGINCCHG as int, @BLDGHEIGHT as int, @BLDGHEIGHTCHG as int, @WETPERCENT as float, @WETPERCENTCHG as int, @RETDBASN as int, @RETDBASNCHG as int, @EXEMPT as int, @EXEMPTCHG as int, @MULTIPLEBLDG as int, @MULTIPLEBLDGCHG as int, @BENEFIT as money, @BENEFITCHG as int, @PARTPROT as int, @PARTPROTCHG as int
declare @cmd as nvarchar(700) declare @cmdM as varchar(400), @fldsM as varchar(300) set @cmdM = 'UPDATE ParcelMaster SET ' declare @cmdP as varchar(400), @fldsP as varchar(300) set @cmdP = 'UPDATE Parcels SET '
-- Analyse what fields should be updated in child table Parcels from parent table ParcelMaster open @cur_Master fetch from @cur_Master into @PID, @BLDGINC, @BLDGINCCHG, @BLDGHEIGHT, @BLDGHEIGHTCHG, @WETPERCENT, @WETPERCENTCHG, @RETDBASN, @RETDBASNCHG, @EXEMPT, @EXEMPTCHG, @MULTIPLEBLDG, @MULTIPLEBLDGCHG, @BENEFIT, @BENEFITCHG, @PARTPROT, @PARTPROTCHG while @@fetch_status = 0 begin set @cmd = '' set @fldsM = '' set @fldsP = ''
if @BLDGINCCHG = 1 begin set @fldsM = @fldsM + 'BLDGINCORG = p.BLDGINC,' set @fldsP = @fldsP + ' BLDGINC = ' + cast(@BLDGINC as varchar(10)) + ',' end
if @BLDGHEIGHTCHG = 1 begin set @fldsM = @fldsM + 'BLDGHEIGHTORG = p.BLDGHEIGHT,' set @fldsP = @fldsP + ' BLDGHEIGHT = ' + cast(@BLDGHEIGHT as varchar(10)) + ',' end
if @WETPERCENTCHG = 1 begin set @fldsM = @fldsM + 'WETPERCENTORG = p.WETPERCENT,' set @fldsP = @fldsP + ' WETPERCENT = ' + cast(@WETPERCENT as varchar(10)) + ',' end
if @RETDBASNCHG = 1 begin set @fldsM = @fldsM + 'RETDBASNORG = p.RETDBASN,' set @fldsP = @fldsP + ' RETDBASN = ' + cast(@RETDBASN as varchar(10)) + ',' end
if @EXEMPTCHG = 1 begin set @fldsM = @fldsM + 'EXEMPTORG = p.EXEMPT,' set @fldsP = @fldsP + 'EXEMPT = ' + cast(@EXEMPT as varchar(10)) + ',' end
if @MULTIPLEBLDGCHG = 1 begin set @fldsM = @fldsM + 'MULTIPLEBLDGORG = p.MULTIPLEBLDG,' set @fldsP = @fldsP + 'MULTIPLEBLDG = ' + cast(@MULTIPLEBLDG as varchar(10)) + ',' end
if @BENEFITCHG = 1 begin set @fldsM = @fldsM + 'BENEFITORG = p.BENEFIT,' set @fldsP = @fldsP + 'BENEFIT = ' + cast(@BENEFIT as varchar(10)) + ',' end
if @PARTPROTCHG = 1 begin set @fldsM = @fldsM + 'PARTPROTORG = p.PARTIALPROT,' set @fldsP = @fldsP + 'PARTPROT = ' + cast(@PARTPROT as varchar(10)) + ',' end
if substring(@fldsM, len(@fldsM), 1) = ',' set @fldsM = substring(@fldsM, 1, len(@fldsM) - 1)
if substring(@fldsP, len(@fldsP), 1) = ',' set @fldsP = substring(@fldsP, 1, len(@fldsP) - 1) -- Backup data in ParcelMaster from Parcels if len(@fldsM) > 0 begin set @cmd = @cmdM + @fldsM + ' FROM ParcelMaster m INNER JOIN Parcels p ON m.PID = p.PID ' + ' WHERE p.PID = ''' + @PID + '''' + ';' end
-- Update Parcels by new values from ParcelMaster if len(@fldsP) > 0 begin set @cmd = @cmd + @cmdP + @fldsP + ' WHERE PID = ''' + @PID + '''' end if len(@cmd) > 0 begin --print @cmd execute sp_executesql @cmd end
fetch from @cur_Master into @PID, @BLDGINC, @BLDGINCCHG, @BLDGHEIGHT, @BLDGHEIGHTCHG, @WETPERCENT, @WETPERCENTCHG, @RETDBASN, @RETDBASNCHG, @EXEMPT, @EXEMPTCHG, @MULTIPLEBLDG, @MULTIPLEBLDGCHG, @BENEFIT, @BENEFITCHG, @PARTPROT, @PARTPROTCHG end
deallocate @cur_Master set nocount off
end
|
|
Answer : Error in Stored Proceedure Syntax
|
|
if @PARTPROTCHG = 1 begin set @fldsM = @fldsM + 'PARTPROTORG = p.PARTIALPROT,' set @fldsP = @fldsP + 'PARTIALPROT = ' + cast(@PARTPROT as varchar(10)) + ',' --Change this line end
|
|
|
|