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 |
vaddi
Posting Yak Master
145 Posts |
Posted - 2006-08-23 : 15:31:27
|
Hello I have got a script for checking the status of the database. When I check it for database which are offline, it is not working I mean its not showing up the result.what changes can be made.USE MASTERGODECLARE @dbname VARCHAR(100)deCLARE @Status varchar(100)Declare @Message VARCHAR(8000)set @Message = ''DECLARE dbname_cursor CURSOR FORSELECT name, Cast(Databasepropertyex(name,'Status=offline') as varchar) as status FROM sysdatabases order by nameOPEN dbname_cursorFETCH NEXT FROM dbname_cursor INTO @dbname, @StatusWHILE @@FETCH_STATUS = 0BEGINselect @message = @message + @dbname + ' - ' + @Status + Char(13)FETCH NEXT FROM dbname_cursor INTO @dbname, @StatusENDCLOSE dbname_cursorDEALLOCATE dbname_cursorprint @message EXEC master.dbo.xp_smtp_sendmail@FROM = N'testsql2000@is.depaul.edu',@TO = N'dvaddi@depaul.edu', @server = N'smtp.depaul.edu',@subject = N'Status of sqlserver!',@type = N'text/html',@message = @messageThanks |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-08-23 : 15:57:42
|
You aren't using DATABASEPROPERTYEX correctly. Here's how to do with that function:SELECT name, DATABASEPROPERTYEX(name, 'Status')FROM sysdatabasesUse a CASE statement or a WHERE clause to find those with Status = OFFLINE.Here's how to do it with DATABASEPROPERTY:SELECT name, DATABASEPROPERTY(name, 'IsOffline')FROM sysdatabasesTara Kizer |
 |
|
|
|
|
|
|