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)
 using CURSOR FOR and queris

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-06-19 : 03:57:41
i want to use the cursor over a list of ID that i recive from a select
like this :
quote:

DECLARE authors_cursor CURSOR FOR
SELECT id FROM V_GETID where col1>5 ORDER BY col2


but the thing is that i dont have this select statment made in advance
but rather i build it in a run-time
how can i combine in this case o i will able to go over id's i recive with the cursor
with a dynamic sql select statment
thnaks in advance
peleg


Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-06-19 : 04:02:06
first of all, why do you need a cursor?

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-19 : 04:02:41
Can you explain what you are trying to do with cursor?
There can be better method than what you are doing now

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2006-06-19 : 04:05:01
maybe:

CREATE TABLE #MyIDs
(
seq int IDENTITY(1,1) NOT NULL
id int NOT NULL,
PRIMARY KEY
(
seq
)
)

-- Dynamic SQL can be used here (I think #MyIDs is in Scope)
INSERT INTO #MyIDs (id)
SELECT id FROM V_GETID where col1>5 ORDER BY col2

DECLARE authors_cursor CURSOR FOR
SELECT id FROM #MyIDs ORDER BY seq

Kristen
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-06-19 : 04:09:26
what i am trying to do is this
i have table with Messages
each message has : UserID,MessageBody,TypeMessage(1 to 4 values),CreateDate)

and what i need is based o nthe order of id's that i recive ffrom the dynamic select i need to get for each user the last 10 messages
order by types : 3,1,2
can i do this withought a SP?

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-19 : 04:31:03
Refer point 2
http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx
or post some sample data and the result you want

Madhivanan

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

- Advertisement -