Solved

IF else end structure when doing an IF EXISTS statement

Posted on 2014-12-08
1
94 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
1 Comment
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now