Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do Dynamically Declare A Cursor (Table name) 1

Status
Not open for further replies.

MarkDicken

IS-IT--Management
Jun 5, 2000
55
CH
Basically I want to SOFTCODE "tblTable1" below:-

Declare TableCursor Cursor
GLOBAL
DYNAMIC
For
Select Field1, Field2 from tblTable1

Any Ideas ???

Many Thanks In Advance ...

Regards

Mark Dicken
Dublin, Ireland
 
Hi Mark,
You can create dyanamic sql to create the cursor. Something like this.
----------------------
Your procedure code
.
.
.

DECLARE @sql varchar(100)
SELECT @sql='DECLARE myCursor CURSOR FOR '+
'SELECT myColumn1, myColumn2,... FROM '+
@myTable
EXEC(@sql) --This statement will create the cursor
.
.
.
----------------------

So you can pass @myTable to your procedure.

I hope this will move you in right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top