Sunday, March 25, 2012

Cursor Functionality using SELECT

Hi,

I would like to achieve CURSOR functionality using SELECT statements.

Can someone guide me on how to achieve the task.

If you elaborate your requirement then we can help out, just

from one sentence it is not possible to understand about your problem.

|||

Something crazy like this maybe? (Run the sample against the

pubs database if you have it - job_id is type smallint.)

DECLARE @.id int

SELECT @.id = MIN(job_id) FROM jobs

WHILE @.id IS NOT NULL

BEGIN

PRINT 'Found job id ' + CAST(@.id AS varchar)

SELECT @.id = MIN(job_id) FROM jobs WHERE job_id > @.id

END

No comments:

Post a Comment