• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

Returning values depending on data in column

I have a query in oracle..looking at returning a numeric value of 1 if a column is not NULL and 0.
some folks said that it would be similar to SQL but my query doesn't work.

So the value I want to change is Col2.  Set to 1 if the there is anything in Col2, and 0 if it is NULL.

Select
Col1,
If Col2 is NOT NULL THEN 1
Else 0 NewColName,
Col3,
From Database.
0
TechMonster
Asked:
TechMonster
1 Solution
 
slightwv (䄆 Netminder) Commented:
Select col1, case when col2 is not null then 1 else 0 end mycol from table;
0
 
SharathData EngineerCommented:
Select col1, decode(col2,null,0,1) mycol from table;
0
 
slightwv (䄆 Netminder) Commented:
Decode is still valid but is being phased out.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
sdstuberCommented:
the NVL2 function does exactly the if null else check

Select col1, nvl2(col2,1,0) from table;
0
 
TechMonsterAuthor Commented:
This is the solution I used...thanks
0
 
sdstuberCommented:
why the B?  that's a penalty grade,  what more did you want for an A?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now