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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-04-28 : 08:22:14
|
| Wendy writes "I am running following script:"/* if temp table exists, drop it */IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE [name] LIKE '#zip_dbs%')BEGIN DROP TABLE #zip_dbsEND/* Create temp table used to hold version and supervisor info grabbed by the cursor for all institution databases */CREATE TABLE #zip_dbs (bak_files_name varchar(100)) INSERT INTO #zip_dbs exec master.dbo.xp_cmdshell 'dir "D:\SAM2003DB1\BACKUP\Restores\"' /* select * from #zip_dbs */delete #zip_dbs where rtrim(bak_files_name) not like '%.bak' or bak_files_name not like '%INST%.bak' or bak_files_name is NUlldeclare @filename varchar(100), @zip_file_path varchar(100), @bak_file_path varchar(100) declare db_cursor scroll cursor for select replace(right(rtrim(bak_files_name),33), '.bak','') as filename from #zip_dbsopen db_cursor fetch next from db_cursor into @filename while @@fetch_status = 0 beginset @zip_file_path ='D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.zip' set @bak_file_path ='D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.bak' Exec master.dbo.xp_cmdshell ''D:\SAM2003DB1\backup\restores\wzzip 'D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.zip' 'D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.bak''' fetch next from db_cursor into @filename end close db_cursor deallocate db_cursor "I got the error "Server: Msg 170, Level 15, State 1, Line 37Line 37: Incorrect syntax near '\'."I can't see what's going wrong, can any one help?ThanksWendy " |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-04-28 : 09:08:46
|
| Wendy,not necessary but loose the double quotes here:>>exec master.dbo.xp_cmdshell 'dir "D:\SAM2003DB1\BACKUP\Restores\"' exec master.dbo.xp_cmdshell 'dir D:\SAM2003DB1\BACKUP\Restores\' and change this:Exec master.dbo.xp_cmdshell ''D:\SAM2003DB1\backup\restores\wzzip 'D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.zip' 'D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.bak''' to this:declare @cmd varchar(2000)set @cmd = 'D:\SAM2003DB1\backup\restores\wzzip D:\SAM2003DB1\BACKUP\restores\' + @filename + '.zip D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.bak'Exec master.dbo.xp_cmdshell @cmdBe One with the OptimizerTG |
 |
|
|
wendy
Starting Member
19 Posts |
Posted - 2005-04-28 : 09:48:08
|
TG,It works greate.Thanks!Wendyquote: Originally posted by TG Wendy,not necessary but loose the double quotes here:>>exec master.dbo.xp_cmdshell 'dir "D:\SAM2003DB1\BACKUP\Restores\"' exec master.dbo.xp_cmdshell 'dir D:\SAM2003DB1\BACKUP\Restores\' and change this:Exec master.dbo.xp_cmdshell ''D:\SAM2003DB1\backup\restores\wzzip 'D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.zip' 'D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.bak''' to this:declare @cmd varchar(2000)set @cmd = 'D:\SAM2003DB1\backup\restores\wzzip D:\SAM2003DB1\BACKUP\restores\' + @filename + '.zip D:\SAM2003DB1\BACKUP\restores\'+ @filename + '.bak'Exec master.dbo.xp_cmdshell @cmdBe One with the OptimizerTG
|
 |
|
|
|
|
|
|
|