Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Getting started with cursors

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-04-04 : 09:27:33
I have this simple example from which to start learning to use cursors:


USE ar
GO
DECLARE @mortgage INT
DECLARE @getMortgage CURSOR

SET @getMortgage = CURSOR FOR
SELECT Converted_Mortgage_Number
FROM format_mortgage_history
OPEN @getMortgage
FETCH NEXT
FROM @getMortgage INTO @mortgage
WHILE (@@FETCH_STATUS = 0)
BEGIN
PRINT @mortgage
FETCH NEXT
FROM @getMortgage INTO @mortgage
END
CLOSE @getMortgage
DEALLOCATE @getMortgage
GO


Although it runs, I dont see the Converted_Mortage_Number printed. What have I done wrong please?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-04 : 09:31:24
Do you have records in format_mortgage_history table?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2008-04-04 : 09:52:41
Thanks for that thought.
As basic as it may seem, it had escaped my attention that my previous csv data conversion had not correctly created the column 'Converted_Mortgage_Number' data as expected. It was null!!

Little wonder there was no output to print
Oh, the shame ...
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-04 : 10:03:15
It happens sometimes..nothing to be ashamed of.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -