Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SQL view with If...Then...Else for Column

Posted on 2009-02-17
3
Medium Priority
?
1,598 Views
Last Modified: 2012-05-06
Folks,

Lets say I have the following table:
OriginalDate   NewDate  GoodData Value
1/1/2008        2/2/2008    1                109
1/2/2008        3/3/2008    0                401

I want to create a view with 2 columns: Date, Value
If GoodData = 1, I want Date to show OriginalDate
if GoodData =0, I want Date to show NewDate

so SELECT * FROM View1 would return
Date         Value1
1/1/2008   109
3/3/2009   401
0
Comment
Question by:sfun28
3 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 1000 total points
ID: 23661727
create view View1 as
select case gooddata when 1 then originaldate when 2 then NewDate else null end, value
from YourTable
0
 
LVL 17

Assisted Solution

by:k_murli_krishna
k_murli_krishna earned 1000 total points
ID: 23661792
CREATE VIEW View1(Date, Value1) AS
SELECT CASE GoodData WHEN 1 then OriginalDate WHEN 0 THEN NewDate ELSE null END, VALUE
FROM YourTable;
The ELSE null part is not really required for your exact requirement.
0
 
LVL 1

Author Closing Comment

by:sfun28
ID: 31547873
thanks!!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

564 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