Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
i want to use the cursor over a list of ID that i recive from a selectlike 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 advancebut rather i build it in a run-timehow can i combine in this case o i will able to go over id's i recive with the cursorwith a dynamic sql select statmentthnaks in advancepelegIsrael -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...
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 nowMadhivananFailing to plan is Planning to fail
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 col2DECLARE authors_cursor CURSOR FOR SELECT id FROM #MyIDs ORDER BY seq
Kristen
pelegk2
Aged Yak Warrior
723 Posts
Posted - 2006-06-19 : 04:09:26
what i am trying to do is thisi 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 messagesorder 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 -:)