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.
| Author |
Topic |
|
dataforums
Starting Member
14 Posts |
Posted - 2005-05-05 : 10:43:35
|
| Hi guys,I think this a simple error but i haven't been able to figure out what's wrong with the code below:Declare temp_cur CURSOR FORselect table_name from INFORMATION_SCHEMA.TABLES where table_name like 'SAMP_TMP_%'OPEN temp_curFETCH NEXT FROM temp_cur into @temp_tabWHILE @@FETCH_STATUS <> -1BEGINdeclare t_cur cursor for select * from @temp_tabOPEN t_curFETCH NEXT FROM t_cur INTO @id,..................... @typeWHILE @@FETCH_STATUS <> -1BEGIN-- some operation performedFETCH NEXT FROM t_cur INTO @id,..................... @typeENDCLOSE t_curdeallocate t_curFETCH NEXT FROM temp_cur INTO @temp_tabENDCLOSE temp_curdeallocate temp_cur**********************************************************Any idea what the problem might be?Thanks in Advance! |
|
|
dataforums
Starting Member
14 Posts |
Posted - 2005-05-05 : 11:08:34
|
| I got to know it is not valid to declare a variable in place of an object name.declare t_cur cursor for select * from @temp_tabBut can anyone suggest me as to how i can achieve looping through this table in the variable temp_tab?Thanks! |
 |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2005-05-05 : 12:57:48
|
| Please see the FAQ (http://www.sqlteam.com/faq.asp) for articles on Dynamic SQL.I'd also look at Books Online. I think they have an example where you use dynamic SQL to populate a temporary table and then use a cursor over that. It will be slow though.===============================================Creating tomorrow's legacy systems today.One crisis at a time. |
 |
|
|
|
|
|