Solved

Sql  select statement with if then

Posted on 2011-02-25
3
370 Views
Last Modified: 2012-05-11

I have a if then else statment that is a small portion of a larger statement but i cant seem to figure out syntax.  here is what i am looking for.

select (if por1.U_SIF_Vendprom = null then por1.shipdate else por1.U_SIF_Vendprom) as REQDATE from por1

0
Comment
Question by:notasgoodasyou
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
Comment Utility
select CASE WHEN por1.U_SIF_Vendprom IS NULL then por1.shipdate else por1.U_SIF_Vendprom END as REQDATE from por1
0
 
LVL 23

Expert Comment

by:wdosanjos
Comment Utility
Alternatively:

select ISNULL(por1.U_SIF_Vendprom, por1.shipdate) as REQDATE from por1
0
 
LVL 40

Expert Comment

by:Sharath
Comment Utility
Is the data type of vendprom and shipdate same? you can also try COALESCE.

select COALESCE(por1.U_SIF_Vendprom, por1.shipdate) as REQDATE from por1
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

14 Experts available now in Live!

Get 1:1 Help Now