Solved

Incorrect syntax near the keyword then

Posted on 2014-11-26
2
532 Views
Last Modified: 2014-11-26
I have a sql stored procedure, and I am trying to add an if statement to the sql script. however I keep getting an error message of : "Incorrect syntax near the keyword 'THEN'.  

I then tried making the most simple if statement shown below, and I still get the same error message.

IF 'A' = 'A' THEN SELECT 'Succes'

What am I doing wrong?
0
Comment
Question by:brgdotnet
2 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 250 total points
ID: 40467936
There is no THEN in T-SQL:
IF 'A' = 'A'
  SELECT 'Succes'
ELSE
  SELECT 'Failure'

Open in new window

0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 40467937
Copy-paste the entire T-SQL statement into this question please.

you can't conditionally SELECT a column or not in a SQL statement, but you can conditionally pass a value, like..

SELECT 
   CASE WHEN orange = banana THEN 'Success' ELSE 'Fail' END as status

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

856 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