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)
 Select next record

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-08-07 : 07:37:05
Carlos writes "Hi, I am using MsSql with Power cobol (www.adtools.com)
Is there any way to get next record using select clause

The main ideia is.
In the forms there is a field named "Last Name"
with "LAGES"

if I use Select field1, field2 from table
where name >= @Lastname
sql will bring me up all rows >= LAGES but i want only
the NEXT record, i the user click again , get next and so on

Ok, I could use Cursor, but i think will be slower.

tks
Carlos Lages"

dsdeming

479 Posts

Posted - 2003-08-07 : 07:53:51
You can use SELECT TOP:

SELECT TOP 1 field1, field2
FROM table
WHERE name >= @Lastname

Or you can use SET ROWCOUNT:

SET ROWCOUNT 1

SELECT field1, field2
FROM table
WHERE name >= @Lastname


Dennis
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-08-07 : 09:07:27
quote:
Originally posted by dsdeming

You can use SELECT TOP:

SELECT TOP 1 field1, field2
FROM table
WHERE name >= @Lastname

Or you can use SET ROWCOUNT:

SET ROWCOUNT 1

SELECT field1, field2
FROM table
WHERE name >= @Lastname


Dennis



Without an ORDER BY clause there is nothing to say this will always work.

Jay White
{0}
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-08-07 : 09:18:32
quote:
Ok, I could use Cursor, but i think will be slower.


in this case, I'd say --- i can't believe I'm doing this -- go ahead and use a cursor.

To step through 1 row at a time in a table with a PREV and NEXT button, that's what cursors are designed for so go ahead and use one.

I need to take a shower now..

- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-08-07 : 10:12:35
quote:
Originally posted by jsmith8858

quote:
Ok, I could use Cursor, but i think will be slower.


in this case, I'd say --- i can't believe I'm doing this -- go ahead and use a cursor.

To step through 1 row at a time in a table with a PREV and NEXT button, that's what cursors are designed for so go ahead and use one.

I need to take a shower now..

- Jeff



AAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

Did you accept money for that?

I'd like to know what he's trying to accomplish?



Brett

8-)

SELECT POST=NewId()
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-08-07 : 12:54:34
If the software is .Net enabled, don't bother with cursors. ADO.Net has TONS of methods available to navigate through a set of results. It pretty much does it automatically, you don't have to do a lot to get it to page records.

You may want to visit a few .Net sites before you get too involved with the data access layer. They probably won't be COBOL, but you'll still get a lot of background on what .Net can do. I strongly recommend the "In-Depth DataGrid" series on [url]http://www.4guysfromrolla.com/[/url] as a start.
Go to Top of Page
   

- Advertisement -