Tuesday, March 27, 2012

Cursor issues

I can get it to create the proc, but it dosen't replace the variable or loop through the select list from ziptrendindex.

Any ideas on what I'm missing?

declare @.countyname varchar (200)

declare @.sql varchar(8000)

declare county_name cursor for

select distinct county from ZipTrendIndex

open county_name

fetch next from county_name

into @.countyname

WHILE @.@.FETCH_STATUS = 0

BEGIN

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[county'+@.countyname+']') AND type in (N'U'))

BEGIN

set @.sql = 'CREATE PROCEDURE dbo.getUpdRecords AS

SET NOCOUNT ON

Declare @.PropertyID bigint

Declare @.PropertyIDBuffer bigint

Declare @.AVMValue float

Declare @.Confidence float

Declare @.a bigint

Declare @.b smallint

Set @.a = 1

Set @.b = 0

While (@.a) > 0

Begin

Select top 1 @.PropertyIDBuffer = sa_property_id from county_name (NOLOCK) Where replyavm is null

If @.PropertyIDBuffer is not null Or @.PropertyIDBuffer > 0

Begin

Set @.b = 0

DECLARE Property_Details CURSOR FOR

Select top 50 sa_property_id

From county_name (NOLOCK)

Where replyavm is null

OPEN Property_Details

FETCH NEXT FROM Property_Details

INTO @.PropertyID

WHILE @.@.FETCH_STATUS = 0

BEGIN

Set @.AVMValue = 0

Set @.Confidence = 0

exec usp_ReplyAVMCalculationcounty_name @.PropertyID, @.AVMValue output, @.Confidence output

If @.AVMValue is Null

Begin

Set @.AVMValue = 0

Set @.Confidence = 0

End

Update county_name

Set ReplyAVM = @.AVMValue,

ReplyScore = @.Confidence

Where sa_property_id = @.PropertyID

FETCH NEXT FROM Property_Details

INTO @.PropertyID

END

CLOSE Property_Details

DEALLOCATE Property_Details

End

Else

Set @.a = 0

End

SET NOCOUNT OFF

GO

SET QUOTED_IDENTIFIER OFF

GO

'

exec (@.sql)

end

fetch next from county_name into @.countyname

end

CLOSE county_name

DEALLOCATE county_name

One quick look and I found you are not setting @.sql to '' while looking through.

exec (@.sql)

end

SET @.sql = ''

fetch next from county_name into @.countyname

end

|||

Thanks!!

That did the trick!!

No comments:

Post a Comment