Solved

sql query

Posted on 2016-11-09
5
68 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
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 33

Expert Comment

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now