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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:47:44+00:00 2026-05-19T23:47:44+00:00

Let’s imagine there is a table Product with columns ProductId (smallint), Title (nullable nvarchar(100))

  • 0

Let’s imagine there is a table Product with columns ProductId (smallint), Title (nullable nvarchar(100)) and Price (money). A title can be null.

There is a query which must return the products matching a specific title and a specific price:

using (SqlCommand getProducts = new SqlCommand("select ProductId from Product where Title = @title and Price = @price", sqlConnection))
{
    getProducts.Parameters.AddWithValue("@title", title);
    getProducts.Parameters.AddWithValue("@price", price);
}

When executing the following code with title set to null (or probably also to an empty string), for SQL Server, the comparison will be:

[...] where Title = NULL and Price = 123

which will return an empty set, since the correct syntax is:

[...] where Title is NULL and Price = 123

I could change the query string according to the null check of the title, but it will be unmaintainable.

Is there a clean way to make the comparison work without making the query string different when Title is null?

  • 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-19T23:47:45+00:00Added an answer on May 19, 2026 at 11:47 pm
    [...] WHERE COALESCE(Title,'') = COALESCE(@Title,'') AND Price = 123
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's aggregate a list of free quality web site design templates. There are a
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say there is a graph and some set of functions like: create-node ::
Let's say I wanted to remove vowels from HTML: <a href=foo>Hello there!</a>Hi! becomes <a
Let's say I have an abstract parent class called shape, and that there are
Let's say I have table with column 'URL' whrere I store urls like this
Let's consider the following scenario: I've a master table with a detail table. The
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's imagine I have a Java class of the type: public class MyClass {
Let's say I have this MySQL table: OK.. see the type field? Type 0

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.