dbTalk Databases Forums  

Dynamic Cursor Generation..

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Dynamic Cursor Generation.. in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Arijit Chatterjee
 
Posts: n/a

Default Dynamic Cursor Generation.. - 11-04-2003 , 11:04 PM






Hi Everybody,
I have a probs with dynamic generation.
I am writing the probs
======================================
create proc test
as
declare @query varchar(500)
set @query = 'select * from table'
----------------------------------------------
declare mycur Cursor for Select * from table |
open mycur |
----------------------------------------------
but instate of above block how can I dynamically generate this query?
---------------------------------------
declare mycur Cursor for exec (@query) |
---------------------------------------
Or tell me the way.
Regards
Arijit Chatterjee

Reply With Quote
  #2  
Old   
Raghu Raman
 
Posts: n/a

Default Re: Dynamic Cursor Generation.. - 11-05-2003 , 12:31 AM






hi, the problem was not clear what u want to do dynamiclly.
if u want to ftech rows thru proc, u can code like

create proc test
as
use db
exec(select * from table)


this might work



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
  #3  
Old   
Chad Gould
 
Posts: n/a

Default Re: Dynamic Cursor Generation.. - 11-05-2003 , 09:46 AM



On 4 Nov 2003 21:04:27 -0800, arijitchatterjee123 (AT) yahoo (DOT) co.in (Arijit
Chatterjee) wrote:
Quote:
but instate of above block how can I dynamically generate this query?
---------------------------------------
declare mycur Cursor for exec (@query) |
---------------------------------------
The way I've done stuff like this in the past is to stuff the results
into a temp table and run a cursor off that.

Example:
declare @SQLstring varchar(100)
create table #foo (foovar int)

select @SQLString = 'select distinct foovar from footable'

insert into #foo exec(@SQLString)

declare foo_cursor for select distinct foovar from #foo
etc.

Obviously you really want to do this type of stuff when there is no
other way around it.

Quote:
Or tell me the way.
Regards
Arijit Chatterjee

Reply With Quote
  #4  
Old   
walid kayrouz
 
Posts: n/a

Default RE: Dynamic Cursor Generation.. - 07-30-2007 , 01:56 AM



i have Been Declare a dynamic cursor to a query ==> select location_en from ...
when i make update to the table, dynamic cursor take changes.
when i declare same cursor with the query select distinct location_en ... and update to the table, dynamic cursor does not take changes.
any idea to this probleme? thx for ur reply

From http://www.google.com/search?hl=en&q="Dynamic+Cursor"+++"For+Select+Dist inct"

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Reply With Quote
  #5  
Old   
Ed Murphy
 
Posts: n/a

Default Re: Dynamic Cursor Generation.. - 08-02-2007 , 09:15 PM



walid kayrouz wrote:

Quote:
i have Been Declare a dynamic cursor to a query ==> select location_en from ...
when i make update to the table, dynamic cursor take changes.
when i declare same cursor with the query select distinct location_en ... and update to the table, dynamic cursor does not take changes.
any idea to this probleme? thx for ur reply

From http://www.google.com/search?hl=en&q="Dynamic+Cursor"+++"For+Select+Dist inct"

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
The standard advice for cursors is "avoid using them if at all
possible". Explain what you're currently doing with them, and the
gurus may be able to offer more specific answers.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.