Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Syntax question

Status
Not open for further replies.

edwindow

Programmer
Jul 13, 2001
51
US
I am creating this view and I wanted to know if there is a way to create a special if/then statement within the select statement. Everything I need is in the same table. I need to select another field in the same table if one table is equal to home.

EX. IF transactions=HOME then department else transactions.

Ex.
the statement I came up with is

create view test select x, x, (transactions='HOME'(select department from deptname)) as transactions
from table;

Is there anyway to do this. The goal is to populate the transactions field with another value from another field only if this condition is true.

Any help on this one would be much appreciated.

Ed
 
Another possibility is to use a "CASE" expression in your SQL statement. A "CASE" is somewhat easier to read than a call to decode. Also, it appears that the columns you want are from two different tables. If this is the case, you will probably have to join the two tables.



 
or

select blah, blah, null from blah where transations <> 'home'
union all
select blah, blah, blah from blah where transations = 'home' I tried to remain child-like, all I acheived was childish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top