Count fields that aren't null across Record?

Count fields that aren't null across Record?

Post by BEE » Fri, 12 Dec 2003 23:27:43



This is the result I would like to have:

RowID   provid  LastDate    lastname   firstname  RecVal
------- ------- ----------- ---------  ---------- ----
201307  118498  2003-01-10             JOY NOEL   4
377532  118498  1973-12-11  NOEL       JOY        5  

RecVal says four fields are not null or not blank
for RowID 201307 and 5 for RowID 377532

Any input on directions I could go to get this value?

Thanks in advance.
B

 
 
 

Count fields that aren't null across Record?

Post by Aaron Bertrand - MV » Fri, 12 Dec 2003 23:38:24


In the first row, is lastname blank, or is it actually NULL?

If NULL, then

SELECT
    RowID, provid, LastDate, lastname, firstname, RecVal =
    CASE WHEN RowID IS NULL THEN 1 ELSE 0 END
    + CASE WHEN provid IS NULL THEN 1 ELSE 0 END
    + CASE WHEN LastDate IS NULL THEN 1 ELSE 0 END
    + CASE WHEN lastname IS NULL THEN 1 ELSE 0 END
    + CASE WHEN firstname IS NULL THEN 1 ELSE 0 END
FROM table

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


Quote:> This is the result I would like to have:

> RowID   provid  LastDate    lastname   firstname  RecVal
> ------- ------- ----------- ---------  ---------- ----
> 201307  118498  2003-01-10             JOY NOEL   4
> 377532  118498  1973-12-11  NOEL       JOY        5

> RecVal says four fields are not null or not blank
> for RowID 201307 and 5 for RowID 377532

> Any input on directions I could go to get this value?

> Thanks in advance.
> B


 
 
 

Count fields that aren't null across Record?

Post by Trey Walpol » Sat, 13 Dec 2003 00:14:01


select rowid, provid, lastdate, lastname, firstname,
    case when nullif(coalesce(rowid,''),'') is not null then 1 else 0 end +
    case when nullif(coalesce(provid,''),'') is not null then 1 else 0 end +
    case when nullif(coalesce(lastdate,''),'') is not null then 1 else 0 end
+
    case when nullif(coalesce(lastname,''),'') is not null then 1 else 0 end
+
    case when nullif(coalesce(firstname,''),'') is not null then 1 else 0
end
as RecVal
from theTable


Quote:> This is the result I would like to have:

> RowID   provid  LastDate    lastname   firstname  RecVal
> ------- ------- ----------- ---------  ---------- ----
> 201307  118498  2003-01-10             JOY NOEL   4
> 377532  118498  1973-12-11  NOEL       JOY        5

> RecVal says four fields are not null or not blank
> for RowID 201307 and 5 for RowID 377532

> Any input on directions I could go to get this value?

> Thanks in advance.
> B

 
 
 

Count fields that aren't null across Record?

Post by BEE » Sat, 13 Dec 2003 00:23:25


Expaning the case statement has taken care of blanks and
nulls (using len() )  Thanks.  This does the trick for me.
B.

>-----Original Message-----
>In the first row, is lastname blank, or is it actually
NULL?

>If NULL, then

>SELECT
>    RowID, provid, LastDate, lastname, firstname, RecVal
=
>    CASE WHEN RowID IS NULL THEN 1 ELSE 0 END
>    + CASE WHEN provid IS NULL THEN 1 ELSE 0 END
>    + CASE WHEN LastDate IS NULL THEN 1 ELSE 0 END
>    + CASE WHEN lastname IS NULL THEN 1 ELSE 0 END
>    + CASE WHEN firstname IS NULL THEN 1 ELSE 0 END
>FROM table

>--
>Aaron Bertrand
>SQL Server MVP
>http://www.aspfaq.com/


message

>> This is the result I would like to have:

>> RowID   provid  LastDate    lastname   firstname  
RecVal
>> ------- ------- ----------- ---------  ---------- ----
>> 201307  118498  2003-01-10             JOY NOEL   4
>> 377532  118498  1973-12-11  NOEL       JOY        5

>> RecVal says four fields are not null or not blank
>> for RowID 201307 and 5 for RowID 377532

>> Any input on directions I could go to get this value?

>> Thanks in advance.
>> B

>.

 
 
 

1. PDox 5: form input fields that AREN't table fields

In PDox 5, I am trying to write a brand new form that asks for some user input.
On the form, there is a command button that will (in objectPal) use the results of these queries.

I want to do the following:

1.      Have a series of three radio buttons (i.e., only one can be checked) and from the command button
        elsewhere on the form, figure out which one got pressed.  I want to set a default.

2.      Have a checkbox, and from the command button (elsewhere) figure out if it got checked.
        I also want to set a default.

3.      Have an input field where the user must enter a number from 1-100, and have the command button
        figure out what number got entered.  I also want to set a default.

The field tool seems to be what I should be using, but it seems oriented towards only fields that are in Paradox tables.
These aren't -- I want to input some user values and have the ObjectPal routine take things from there.

So:
1.      Should I be using the field tool for this?
2.      How do I name the fields, set defaults, and get results generated so the command button's method will be able to
        figure out what the current values are?

2. Has anyone used Universal Smart Drive (usb storage devcie) for Backing up data??

3. Autonumbering fields aren't working

4. Choosing a Character Set

5. Autoincrement fields aren't updated when CacheUpdates=true

6. How to design a report generator

7. force NULL in fields that don't allow NULL

8. Accounting Source Code

9. counting record only when field value is not equal to value of previous record

10. Counting 'hits' on text fields

11. not null column during CTAS(not null definition did not come across)

12. Error that stored procedures aren't in collection, but they're listed in EM