Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:17:39+00:00 2026-05-27T22:17:39+00:00

A number of times over the last month I’ve had to replace ‘null’ fields

  • 0

A number of times over the last month I’ve had to replace ‘null’ fields with ‘0’ to every column returned from a query.

to save a lot of time (some of these are returning a high number of columns) I’ve been using the following and then pasting the results for relevant columns into a new query:

select      ',  isnull(' + COLUMN_NAME + ', 0)' + ' as ' + COLUMN_NAME
from        INFORMATION_SCHEMA.COLUMNS
where       TABLE_NAME = 'summary_by_scca_sales_category '
            and TABLE_SCHEMA = 'property''

Essentially I’m wondering if there’s a better way that I can do this? Ideally a method where I could automatically apply isnull to all columns being returned in a query (without using two queries).

For example:

I want to take a query like:

select  *
from    tablename

And for every column returned by * replace null results with 0 without having to write an isnull() line for each column.

edit:

Will accomplish this with a view (doh, should have thought of that). For interests / educations sake is there a way to do something like this with code also?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:17:40+00:00Added an answer on May 27, 2026 at 10:17 pm

    You could create a VIEW against the tables in question where the ISNULL logic you want is set up. Then queries against the views would return the data you want.

    EDIT:

    As requested, some sample code to accomplish creating the VIEWs automatically. This is pretty gross, but for something that only has to be run once it will work. Beware of type issues (you stated everything should transmute to 0 so I assume all your columns are of a suitable numeric type):

    DECLARE @table_def varchar(max)
    SET @table_def = 'CREATE VIEW <tname>_NoNull AS SELECT '
    
    SELECT @table_def = REPLACE(@table_def, '<tname>', t.name) + 
        'ISNULL(' + c.name + ', 0) AS ' + c.name + ', '
    FROM sys.tables t
        INNER JOIN sys.columns c ON t.object_id = c.object_id
    WHERE t.name = <<table name>>
    
    SELECT @table_def
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to show the number of times an operation occurred since the last
Over the last few months, there have been a number of rapid developments in
Last month we had an issue with a commission payment. The dollar amount exceeded
I tried numerous times over the last few weeks to get a server side
We have a number of AS/Flex components that we've built over time and improved
A number of times I've argued that using clone() isn't such a bad practice.
I am trying to count the number of times a user has clicked on
I'm trying to count the number of times that -- occurs in a string.
This chart has been linked a number of times on blogs that I follow
i want to reduce the number of times i hit the data base to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.