Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Count of non null columns in a row

Count of non null columns in a row

Scheduled Pinned Locked Moved Database
databasehelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bhanu12345
    wrote on last edited by
    #1

    Hi, Can any body help me in writing a query to retrieve the count of non null columns in a particular row. For eg: I have 30 columns in a table and I enter values to only 5 columns. when I run the query I should get the output as 5 columns have non null values. If it is not possible then is it possible to read values of different columns of a single row into a single variable. Please help me out. ABC

    P D 2 Replies Last reply
    0
    • B bhanu12345

      Hi, Can any body help me in writing a query to retrieve the count of non null columns in a particular row. For eg: I have 30 columns in a table and I enter values to only 5 columns. when I run the query I should get the output as 5 columns have non null values. If it is not possible then is it possible to read values of different columns of a single row into a single variable. Please help me out. ABC

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      AFAIK, the only way of doing this would be to loop through the columns and count the number of fields with a NULL value. You may want to consider whether your database design is optimal for the type of work you are doing.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      1 Reply Last reply
      0
      • B bhanu12345

        Hi, Can any body help me in writing a query to retrieve the count of non null columns in a particular row. For eg: I have 30 columns in a table and I enter values to only 5 columns. when I run the query I should get the output as 5 columns have non null values. If it is not possible then is it possible to read values of different columns of a single row into a single variable. Please help me out. ABC

        D Offline
        D Offline
        Dave B
        wrote on last edited by
        #3

        Its Not pretty but... select case when _cola_ is null then 1 else 0 end+ case when _colb_ is null then 1 else 0 end+ ................... from _table_

        modified on Friday, January 11, 2008 3:53:29 AM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups