FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Strange SQL cursor problem. Pls do not ignore if can help.





shamil
I have table called material_info with below create code.
Code:
CREATE TABLE [dbo].[material_info](
   [material_info_id] [int] IDENTITY(1,1) NOT NULL,
   [material_id] [int] NULL,
   [amount_type_id] [int] NULL,
   [mat_kod] [varchar](4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_material_info] PRIMARY KEY CLUSTERED
(
   [material_info_id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO

I use a cursor in stored proc which declared as
Code:
declare mycurs cursor LOCAL  for select mat_kod from material_info order by mat_kod;

Code:
OPEN mycurs   
FETCH NEXT FROM mycurs INTO @mycurKod 
--FETCH NEXT FROM mycurs INTO @mycurKod
WHILE @@FETCH_STATUS = 0
BEGIN
   insert into my values(@mycurKod)
   /* my code */
   FETCH NEXT FROM mycurs INTO @mycurKod
END


Problem is that the first fetch doesn't work it returns null so i have to use double fetch before going into loop. I tried cursor sql independently to see if there is null value but there isin't.
But whenever i take off order by clause it works. But i need order by also. Why this happens?
I will really appreciate your help.
albuferque
Try to change FORWARD_ONLY setting of the cursor

http://www.teratrax.com/articles/sql_server_cursor.html

Hope that helps.
shamil
Thanks for your reply.
It has been already solved. Problem was i inserted null into table and executed cursor before updating null to new value;
Related topics
Strange Fire fox problem
Seriously strange Phpbb forum problem
same problem over here...
Webpage Display Problem
Major Problem with COmputer. Help Please
Serious Problem
MS Support site seem to be down
windows amazing problem OR computer hardware problem
PHP website with SQL Database.
Dell Inspiron 1564 laptop problem, pls help!
Header("Location: PROBLEM");
Need help.. I don't Know wats the problem but plz help me
Firefox/IE compatibility problem, need some help
LAN is one-way & takes a click to be two-way. Why?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.