shamil
I have table called material_info with below create code.
I use a cursor in stored proc which declared as
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.
| 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.
