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 2000 Forums
 SQL Server Development (2000)
 Help in Cursors

Author  Topic 

Radhiga
Starting Member

35 Posts

Posted - 2006-04-18 : 22:01:04
Hello friends,
im new to use Cursors.

while (@@fetch_Status = 0)
begin
fetch Cur_ri into
@COMPANY ,@STARTIME ,@ENDTIME

SELECT @COMPANY
@STARTIME,
@ENDTIME

end
close Cur_ri
Deallocate cursor...
It is returning 10 records and all the 10 records ssq no is 1..
is that mean when i capture in the .net front end will it return 10 difference datatable..
is this behaviour right...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-18 : 22:03:56
Yes. your one SELECT statement will return as one result set so if you have 10 records, it will be 10 result set.

Why do you need to use cursor ?

you can just
SELECT company, starttime, endtime from yourtable

and it will return all 10 records in a single result set



KH


Go to Top of Page

Radhiga
Starting Member

35 Posts

Posted - 2006-04-18 : 22:07:46
Is it possible to select all the 10 records in one select statment...
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-04-18 : 22:08:56
yes, sql is designed to do just that...

you can even do batch processing

--------------------
keeping it simple...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-18 : 22:10:13
quote:
Originally posted by Radhiga

Is it possible to select all the 10 records in one select statment...


Yes. See my earlier post



KH


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-19 : 03:09:48
Radhiga, It seems that you are very much interested in using Cursors(from some of your posts)
In most cases, that can be done very easily. Tell us what you are trying to do. Post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Krankensteins
Starting Member

24 Posts

Posted - 2006-04-19 : 05:07:52
Whay not sou:
Open cursor

fetch Cur_ri into
@COMPANY ,@STARTIME ,@ENDTIME

while (@@fetch_Status = 0)
begin

SELECT @COMPANY
@STARTIME,
@ENDTIME

fetch Cur_ri into
@COMPANY ,@STARTIME ,@ENDTIME
end
close Cur_ri
Deallocate cursor...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-19 : 05:22:06
>>Whay not sou:

What language is this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Radhiga
Starting Member

35 Posts

Posted - 2006-04-19 : 05:44:52
THANKS MR.MADHIVANAN.MY REQUIRMENT IS LIKE THAT...NEED TO MAP TWO DIFFERENT TABLES WHICH DOESNT HAVE ANY MAPPING IN BETWEEN BUT WITH THE DATA WE CAN MAP IT..THAT'S Y I WANTED TO USE CURSOR..
I HAVE FIXED THAT ONE
THANKS.
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-04-19 : 05:45:10

quote:

What language is this?



Latvian or other name i guess Lettish???

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-04-19 : 05:46:51
quote:
Originally posted by Radhiga

THANKS MR.MADHIVANAN.MY REQUIRMENT IS LIKE THAT...NEED TO MAP TWO DIFFERENT TABLES WHICH DOESNT HAVE ANY MAPPING IN BETWEEN BUT WITH THE DATA WE CAN MAP IT..THAT'S Y I WANTED TO USE CURSOR..
I HAVE FIXED THAT ONE
THANKS.



Can you post some sample data of both the tables ..?? and how are you going to map them ??

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

Krankensteins
Starting Member

24 Posts

Posted - 2006-04-19 : 07:01:51
{Sory} as follow:
Declare T Cursor for select top 10 OrderID,CustomerID from dbo.Orders
Declare @ID int
Declare @Cus nchar(5)
Open T
fetch T into @ID ,@Cus
while (@@fetch_Status = 0)
begin
SELECT @ID, @CUS
fetch T into @ID ,@Cus
end
Close T
Deallocate T
Go to Top of Page
   

- Advertisement -