Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Incorrect syntax near the keyword then

Posted on 2014-11-26
2
Medium Priority
?
651 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 71

Accepted Solution

by:
Qlemo earned 1000 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 1000 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

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

783 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