Solved

Incorrect syntax near the keyword then

Posted on 2014-11-26
2
580 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
[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
2 Comments
 
LVL 70

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 66

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

635 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