How to write a sql statement to find the first occurrence of a non zero value?

Showing Answers 1 - 12 of 12 Answers

Tatyana

  • Apr 5th, 2006
 

Sorry guys,

There is a slight chance the column "a" has a value of 0 which is not null. In that case, You'll loose the information. There is another way of searching the first not null value of a column:

select column_name from table_name where column_name is not null and rownum<2;

  Was this answer useful?  Yes

Mainak Aich

  • Apr 6th, 2006
 

There's another way to do the same thing ::select col from tabname where rowid =(select min(rowid) from tabname where col is not null)here col is column name and tabname is table name.

  Was this answer useful?  Yes

Tatyana

  • Apr 8th, 2006
 

Just want to notice that the last SQL statement will take much more time then the previous one.

  Was this answer useful?  Yes

madhu

  • Apr 13th, 2006
 

Hai here the query is for non zero value right that time what is the problem even if it is null so we can write like this select columnname from tablename where columnname<>0 and rownum<2

  Was this answer useful?  Yes

ed Di

  • Apr 18th, 2006
 

there is no first occurance in a relational database. These queries using rownum and the like are quite arbitrary. After a reorg, all of those queries would probable return different rows.

There is no implied order to the rows or columns in the tables of a relational database.

SQL Devotee

  • Jan 15th, 2007
 


Use coalesce.
Eg:
select coalesce(NULL,NULL,NULL,NULL,1,NULL,NULL,'a')
This will give you 1 as the result.

  Was this answer useful?  Yes

Bharath

  • Sep 6th, 2007
 

Actually the query returns an error like "expected NUMBER got CHAR"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions