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 7928427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:43:43+00:00 2026-06-03T19:43:43+00:00

I have a database table with many columns. Is there sql that will update

  • 0

I have a database table with many columns. Is there sql that will update records in that table where all or only specific columns are handled in such a way that if NULL is passed for any column value that the existing value not be changed?


Currently I can use solutions like these

UPDATE table
    SET column1 = COALESCE(@param1, column1),
        column2 = COALESCE(@param2, column2),
        ...
    WHERE id = @id

or

UPDATE table
set   column1 = isnull(@param1,column1),
      column2 = isnull(@param2,column2)

They both works well, though sometimes I want to explicitly save null in any column and I can’t do it with the above solutions. How?

  • 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-06-03T19:43:44+00:00Added an answer on June 3, 2026 at 7:43 pm

    One approach is to declare two parameters for each column, the first contains the value, the second is a bit instructs the query to insert null explicitly.

    Example
    create table example (column1 nvarchar(255), column2 nvarchar(255))
    
    create procedure pUpdate(
        @column1 nvarchar(255)  = null,
        @nullColumn1 tinyint    = 0,
        @column2 nvarchar(255)  = null,
        @nullColumn2 tinyint    = 0
        ) as
        BEGIN
        
        update example 
            set column1 = Case When @nullcolumn1 = 1 
                               Then NULL ELSE IsNull(@column1, column1) End
            set column2 = Case When @nullcolumn2 = 1 
                               Then NULL ELSE IsNull(@column2, column2) End
    
        END
    

    Then when calling from code, you only have to pass the parameters that you know need updating, or explicitely set the @nullcolumn to force a null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table within my database that has many records, some records share
Many applications have grids that display data from a database table one page at
I have a database table in SQL Server 2005 Express that takes in 2367
Here is what i have: a SQL CE database, that holds this Category table,
I have database with many tables. In the first table, I have a field
I have the following tables in my database that have a many-to-many relationship, which
that my problem: I have database table like that: id (AI) market_id 1 6
I have a legacy mysql database and there's this table which has a few
The Query Optimizer is estimating that the results of a join will have only
I have a database table like that :- Table1 Column1 : Varchar(50) Column2 :

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.