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
Solved

Sql  select statement with if then

Posted on 2011-02-25
3
395 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
ID: 34984501
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
ID: 34984675
Alternatively:

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

Expert Comment

by:Sharath
ID: 34985026
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …

860 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