Solved

sql query

Posted on 2016-11-09
5
87 Views
Last Modified: 2016-11-10
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?
0
Comment
Question by:sam shah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41881717
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
 
LVL 10

Expert Comment

by:HuaMinChen
ID: 41881786
Try
Update Tab1
set col1=(select count(1) from Tab2 where nvl(col2,'')<>'');

Open in new window

0
 
LVL 34

Expert Comment

by:ste5an
ID: 41881808
There is no such think like a null row. What is your concrete problem?
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 41882073
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
 
LVL 32

Expert Comment

by:awking00
ID: 41882116
Sample data with table names and structures, column names and their data types, plus the expected results is ALWAYS helpful.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

738 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