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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:41:26+00:00 2026-05-24T06:41:26+00:00

I have a sql server 2008 table with two nullable decimal values and an

  • 0

I have a sql server 2008 table with two nullable decimal values and an ID. I am passing the values and an ID into a stored procedure. These values may be the same as the existing values, or they may be something else. If it is something else, I want to update the existing record. My question is, I’m not sure how to do this because of the nullable factor.

DECLARE @count int
SET @count=(SELECT Count(ID) FROM [MyTable] WHERE 
  [ID]=@id AND 
  [Value1]<>@value1 AND
  [Value2]<>@value2
)

IF (@count>0)
BEGIN
  UPDATE
    [MyTable]
  SET
    [Value1]=@value1,
    [Value2]=@value2
  WHERE
    [ID]=@id
END

My problem is handling the null case. Can somebody please show me how to handle the null case that I described?

Thank you!

  • 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-24T06:41:27+00:00Added an answer on May 24, 2026 at 6:41 am

    Use ISNULL to provide a default value for Value1 and Value2 in your comparison.
    And I think you’ll want an OR if you you want to update if either value is different.

    SELECT @count = Count(ID) FROM @MyTable 
    WHERE ID = @id 
       AND (ISNULL(Value1,0) <> @value1 OR ISNULL(Value2,0) <> @value2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SQL Server 2008 database with two tables. The first table is called
I have a SQL Server 2008 database with two tables. The first table is
I have two named instances of SQL Server 2008 and am trying to set
I have SQL Server 2008 Ent and OLTP database with two big tables. How
I have SQL Server 2008. I run a query in a table on a
I have a table with two separate columns for date and time (SQL Server
I have two SQL Server 2008 Enterprise databases (on two machines), and one of
I have a couple of tables in a SQL 2008 server that I need
I have tried SQL Server 2008 Management Studio and other third party tools to
I have looked at the SQL Server 2008 feature comparison matrix and it lists

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.