sql query

how to write a pl sql which will count the number of not null rows in a column and update another table with the sum?
sam shahAsked:
Who is Participating?
 
slightwv (䄆 Netminder) Commented:
HuaMinChen,

That won't work.  Oracle treats an empty string as a null.



sam,

To update a COLUMN with the count of not null COLUMNS:
update some_table set some_column=(select count(*) from another_table where some_column is not null);

I suspect the real answer is a little more complex than that.  As Paul and ste5an suggested, can you explain more about the actual requirements?
0
 
PortletPaulfreelancerCommented:
PL/SQL is Oracle, so I  added that topic.
Is ms sql server not relevant?

Could you elaborate on your question with a small example. Include the real tables names and column name you want updated.
0
 
HuaMin ChenSystem AnalystCommented:
Try
Update Tab1
set col1=(select count(1) from Tab2 where nvl(col2,'')<>'');

Open in new window

0
 
ste5anSenior DeveloperCommented:
There is no such think like a null row. What is your concrete problem?
0
 
awking00Commented:
Sample data with table names and structures, column names and their data types, plus the expected results is ALWAYS helpful.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.