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 |
|
neena
Starting Member
10 Posts |
Posted - 2002-04-10 : 18:04:00
|
| I've following code which I want to run on master to enumerate thru databases to get data from one table in each database. Gives me error on dynamic sql. what's the solutions????declare @dbname sysname, @str varchar(2000) DECLARE DB_Cursor CURSOR FOR SELECT name from master..sysdatabases where name not in 'master','tempdb','model','msdb','pubs','Northwind') OPEN DB_Cursor FETCH NEXT FROM DB_Cursor INTO @dbname WHILE @@FETCH_STATUS = 0 BEGIN if @dbname is not null select @dbname set @str = "insert into #DataList select group_name from " + @dbname + ".dbo.TB_PVS_GROUP" exec(@str) FETCH NEXT FROM DB_Cursor INTO @dbname END CLOSE DB_Cursor DEALLOCATE DB_Cursor |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2002-04-10 : 18:53:56
|
| Replace the double quotes with single quotes in your set statement.-Chad |
 |
|
|
|
|
|