Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Incorrect Syntax using IF statement
Hi,

I'm new to SQL Server Programming, I work with ASP a lot, but lately
I've been trying to create Stored Procedures, etc.  I'm having a
problem writing a simple IF statement.. I don't seem to understand why
it's giving me this error.  I've search around on Google Groups, but I
still don't get it.

=================
USE msdb

IF NOT EXISTS (SELECT * FROM sysjobs WHERE name = 'Scheduled Nightfax')

END
=================

My error is:
Server: Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'END'.

Thanks for any help.


Report this thread to moderator Post Follow-up to this message
Old Post
Fergatron
04-06-06 02:30 PM


Re: Incorrect Syntax using IF statement
you need a BEGIN for every END
example

DECLARE @v BIT
SELECT @v = 1

IF @v = 1
BEGIN
select 'yes'
END
ELSE
BEGIN
select 'No'
END


Or without begin...end
IF @v = 1
select 'yes'
ELSE
select 'No'

Denis the SQL Menace
http://sqlservercode.blogspot.com/


Report this thread to moderator Post Follow-up to this message
Old Post
SQL
04-06-06 02:30 PM


Re: Incorrect Syntax using IF statement
Thanks,  I played with it a bit and I got the result I was looking for.

==============
USE msdb
DECLARE @JobName varchar(255)
SELECT @JobName = name FROM sysjobs WHERE name = 'Scheduled Nightfax'

IF @JobName = 'Scheduled Nightfax'
PRINT 'YES'
ELSE
PRINT 'NO'
==============


Report this thread to moderator Post Follow-up to this message
Old Post
Fergatron
04-06-06 02:30 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 07:51 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006