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 variable instead table name

Author  Topic 

stetou
Starting Member

2 Posts

Posted - 2009-01-15 : 09:00:40
I use this command to declare a cursor
declare rst cursor for select col006,col005,age from tablePeople for UPDATE of MoisJour, Age

I need to launch this command in a loop (on several table)
So I would like to use a variable instead of the table name.
I tried this but didn't work:
set @strTable = 'tablePeople'
declare rst cursor for select col006,col005,age from @strTable for UPDATE of MoisJour, Age

How can I use a variable properly when declaring a cursor on a select statement?
thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-15 : 09:02:23
you need to use dynamic sql for this. But can i ask whats the purpose of using this cursor on several table?
Go to Top of Page

stetou
Starting Member

2 Posts

Posted - 2009-01-15 : 09:13:36
This code is part of an ETL to integrate several tables into the database. I need "crunch" each observation of each table before merging them. I declare the cirsor on a table and fetch each row. Then I do the same for the other tables.

I'm good building sql queries but I never created sql server script. I'm not familiar with the syntax and dynamic sql.
Go to Top of Page
   

- Advertisement -