Re: Execute SQL Statment
From: Jacco Schalkwijk (NOSPAMjaccos_at_eurostop.co.uk)
Date: 04/19/04
- Next message: Billy Yao [MSFT]: "Re: Sql Server Trigger that calls Win32.SetEvent"
- Previous message: Buddy Ackerman: "Re: Execute SQL Statment"
- In reply to: CC&JM: "Execute SQL Statment"
- Next in thread: Paul Ibison: "Execute SQL Statment"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 19 Apr 2004 15:10:02 +0100
Use:
EXEC (@dbname)
instead of or right after print @dbname.
-- Jacco Schalkwijk SQL Server MVP "CC&JM" <anonymous@discussions.microsoft.com> wrote in message news:0e4b01c42613$2eeb8e80$a601280a@phx.gbl... > Hello, > > I need to execute "SQL Statments" that belong to a script > but i think that im not doing it in the right way. > I only can print the output, but i dont know how to > execute it. > > I've th following code: > > if (select count(1) from master..sysdatabases) > 0 > > declare dbname_cur cursor for select [name] from > master..sysdatabases > declare @dbname as varchar(500) > declare @sqlstring as varchar(500 > ) > open dbname_cur > fetch next from dbname_cur into @dbname > > WHILE @@FETCH_STATUS = 0 > begin > set @dbname = 'select [name],[filename] from ' + @dbname > + '..sysfiles' > print @dbname > fetch next from dbname_cur into @dbname > end > close dbname_cur > deallocate dbname_cur > > This code give me the following output: > select [name],[filename] from example..sysfiles > select [name],[filename] from master..sysfiles > select [name],[filename] from model..sysfiles > select [name],[filename] from msdb..sysfiles > select [name],[filename] from Northwind..sysfiles > select [name],[filename] from pubs..sysfiles > select [name],[filename] from tempdb..sysfiles > > Now i need to execute this output. > > Best regards >
- Next message: Billy Yao [MSFT]: "Re: Sql Server Trigger that calls Win32.SetEvent"
- Previous message: Buddy Ackerman: "Re: Execute SQL Statment"
- In reply to: CC&JM: "Execute SQL Statment"
- Next in thread: Paul Ibison: "Execute SQL Statment"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|