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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating dynamic cursors

Status
Not open for further replies.

karimdba

Programmer
Joined
Jul 26, 2001
Messages
6
Location
CH
Hi, I want to create cursors with parameter like in Oracle and I've read somewhere that you can't pass parameters(In SQL Server 7 Documentation...)in their declaration.

I want to retrieve all columns for all tables in an other database and i want to make a comparison between mine and the other.
So I create a cursor to get all the tablenames of my database and compare the columns.

I've thought about execute('Declare cListeDetailleTablesRef cursor local
For select a.name ,c.name ,a.prec
from @CH_NOM_SERVEUR+'.'+@CH_NOM_BASE+'.'syscolumns a,
@CH_NOM_SERVEUR+'.'+@CH_NOM_BASE+'.'sysobjects b,
@CH_NOM_SERVEUR+'.'+@CH_NOM_BASE+'.'systypes c
where a.id = b.id
and a.xtype=c.xtype
and b.xtype='U'
and b.name ='+ @CH_NOM_TABLE_REF),

but I'd like to know if there is a solution and if what I've thought was correct.
Thanks by advance,
Regards
 
yep, You thought correct. And, creating the dynamic sql is the only way currenctly in SQL server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top