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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Having problems with if else ??

Author  Topic 

bkpgamble
Starting Member

30 Posts

Posted - 2006-10-04 : 08:35:28
select count(*) INTO IfMailOrNoMail FROM [LagerTilFlow].[dbo].[drives]
where TotalProcentFree < 20
if IfMailOrNoMail != 0
BEGIN
I want to do
sql that sends mail send mail
END

if not delete table with info

problem is I have a fairly large sql I want to send a mail if its true but I just dont seem able to find one that can do the thing I want

anny help would be nice I tried using begin end... but dident work

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-04 : 08:44:38
[code]IF EXISTS (SELECT 1 FROM [LagerTilFlow].[dbo].[drives] WHERE TotalProcentFree < 20)
SEND MAIL
[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

bkpgamble
Starting Member

30 Posts

Posted - 2006-10-04 : 08:55:21
Thanks for the reply I still cant get it to work tho
let me add some more info to the problem :)

IF EXISTS (SELECT 1 FROM [LagerTilFlow].[dbo].[drives] WHERE TotalProcentFree < 20)

DECLARE @TmpMailBody char(1000)

SET @TmpMailBody = 'SELECT * from [LagerTilFlow].[dbo].[drives]'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'xxx',
@recipients = 'My mail',
@subject = 'Database',
@query = @TmpMailBody;

Go
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-04 : 09:00:33
[code]IF EXISTS (SELECT 1 FROM [LagerTilFlow].[dbo].[drives] WHERE TotalProcentFree < 20)
BEGIN
DECLARE @TmpMailBody char(1000)

SET @TmpMailBody = 'SELECT * from [LagerTilFlow].[dbo].[drives]'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'xxx',
@recipients = 'My mail',
@subject = 'Database',
@query = @TmpMailBody;
END[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

bkpgamble
Starting Member

30 Posts

Posted - 2006-10-04 : 09:05:36
That did it

Thanks Peter Larsson
Go to Top of Page
   

- Advertisement -