Solved

Incorrect syntax near the keyword then

Posted on 2014-11-26
2
441 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 68

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

707 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

18 Experts available now in Live!

Get 1:1 Help Now