Solved

sql computed value syntax

Posted on 2007-03-28
4
253 Views
Last Modified: 2010-05-19
Hi,

I want something like

select field1, field2, (field1 is field1 is not null else field2) from mytable

how do I say it correctly?

Thank you.
0
Comment
Question by:kerzner
  • 2
4 Comments
 
LVL 4

Expert Comment

by:mukhtar2t
ID: 18810509
select field1,field2,nvl(field1,field2) from mytable
0
 
LVL 4

Accepted Solution

by:
mukhtar2t earned 500 total points
ID: 18810514
That is for Oracle
for mysql
select field1,field2,ifnull(field1,field2) from mytable
0
 
LVL 1

Author Comment

by:kerzner
ID: 18810548
and this is for sqlserver, which I happened to need

CASE WHEN destid is null Then 0  Else 1 End
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18811531
select field1, field2, COALESCE(field1 , field2) from mytable
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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