?
Solved

IF else end structure when doing an IF EXISTS statement

Posted on 2014-12-08
1
Medium Priority
?
111 Views
Last Modified: 2014-12-08
I want like an if then else structure when I use an IF EXISTS CLAUSE. In that case would the code below be correct where I have two BEGIN END statements ?
---------------------------------
IF  EXISTS ( SELECT Code from zoop where Code = @newPLAYERId)
BEGIN
update zoop
    set Code = '####'  
    from zoop t
    where t.DateEntered > ( select min(x.DateEntered) from zoop x ) -- AND SUBSTRING(t.Code,1,1) = 'A'
END
ELSE
BEGIN

END
0
Comment
Question by:brgdotnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 33

Accepted Solution

by:
knightEknight earned 2000 total points
ID: 40488132
Yes, the if/else structure you have above is correct, but you will need to put at least one valid statement in the ELSE block (it can't be empty).

 The other code looks okay for a sample.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question