Solved

sql query

Posted on 2016-11-09
5
88 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 49

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 11

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

695 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