SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ahmeds08
Aged Yak Warrior

India
573 Posts

Posted - 07/29/2013 :  06:22:59  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
Hi All,
Need help with below query.
there are 10 statements in the query
when i execute the query ,if suppose the first statement fails to execute i want it to continue executing the other statements.how can i do that.


select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S001WS\SQLEXPRESS ' FROM [S001WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S001WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S001WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S002WS\SQLEXPRESS ' FROM [S002WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S002WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S002WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S003WS\SQLEXPRESS ' FROM [S003WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S003WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S003WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S004WS\SQLEXPRESS ' FROM [S004WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S004WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S004WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S005WS\SQLEXPRESS ' FROM [S005WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S005WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S005WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S006WS\SQLEXPRESS ' FROM [S006WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S006WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S006WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S007WS\SQLEXPRESS ' FROM [S007WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S007WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S007WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S008WS\SQLEXPRESS ' FROM [S008WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S008WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S008WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S009WS\SQLEXPRESS ' FROM [S009WS\SQLEXPRESS].master.dbo.sysdatabases a left join[S009WS\SQLEXPRESS].msdb.dbo.backupset b on a.name = b.database_name where b.backup_finish_date = (select max(backup_finish_date) from[S009WS\SQLEXPRESS].msdb.dbo.backupset where database_name = a.name and type = 'D') and a.name not in('Admin') order by a.name


Thanks,
Javeed.

mohammad.javeed.ahmed@gmail.com

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/29/2013 :  06:24:32  Show Profile  Reply with Quote
add a GO between them and execute so that each statement will be in its own batch and will run regardless any error in the other

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/29/2013 :  06:25:17  Show Profile  Reply with Quote
ie like


select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S001WS\SQLEXPRESS ' 
FROM [S001WS\SQLEXPRESS].master.dbo.sysdatabases a 
left join[S001WS\SQLEXPRESS].msdb.dbo.backupset b 
on a.name = b.database_name 
where b.backup_finish_date = (select max(backup_finish_date) 
from[S001WS\SQLEXPRESS].msdb.dbo.backupset 
where database_name = a.name and type = 'D') 
and a.name not in('Admin') 
order by a.name
GO
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S002WS\SQLEXPRESS ' 
FROM [S002WS\SQLEXPRESS].master.dbo.sysdatabases a 
left join[S002WS\SQLEXPRESS].msdb.dbo.backupset b 
on a.name = b.database_name 
where b.backup_finish_date = (select max(backup_finish_date) 
from [S002WS\SQLEXPRESS].msdb.dbo.backupset 
where database_name = a.name and type = 'D') 
and a.name not in('Admin') 
order by a.name
GO
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S003WS\SQLEXPRESS ' 
FROM [S003WS\SQLEXPRESS].master.dbo.sysdatabases a 
left join[S003WS\SQLEXPRESS].msdb.dbo.backupset b 
on a.name = b.database_name 
where b.backup_finish_date = (select max(backup_finish_date) 
from[S003WS\SQLEXPRESS].msdb.dbo.backupset 
where database_name = a.name and type = 'D') 
and a.name not in('Admin') 
order by a.name
GO
select a.name, b.backup_finish_date as LastBackupDate,CAST(CAST(b.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, 'S004WS\SQLEXPRESS ' 
FROM [S004WS\SQLEXPRESS].master.dbo.sysdatabases a 
left join[S004WS\SQLEXPRESS].msdb.dbo.backupset b 
on a.name = b.database_name 
where b.backup_finish_date = (select max(backup_finish_date) 
from[S004WS\SQLEXPRESS].msdb.dbo.backupset 
where database_name = a.name and type = 'D') 
and a.name not in('Admin') 
order by a.name
GO
...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs

Edited by - visakh16 on 07/29/2013 06:27:09
Go to Top of Page

ahmeds08
Aged Yak Warrior

India
573 Posts

Posted - 07/29/2013 :  06:28:35  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
Thanks Visakh.
It worked

mohammad.javeed.ahmed@gmail.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/29/2013 :  06:55:07  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000