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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:23:48+00:00 2026-05-26T17:23:48+00:00

I was searching for integers in a nvarchar column. I noticed that if the

  • 0

I was searching for integers in a nvarchar column. I noticed that if the row contains ” or 0 it is picked up if I search using just 0.

I’m assuming there is some implicit conversion happening which is saying that 0 is equal to ”. Why does it assign two values?

Here is a test:

--0 Test
create table #0Test (Test nvarchar(20))

GO
insert INTO #0Test (Test)
    SELECT ''
UNION ALL
    SELECT 0
UNION ALL
    SELECT ''

Select *
from #0Test

Select *
from #0Test
Where test = 0

SELECT *
from #0Test
Where test = '0'

SELECT *
from #0Test
Where test = ''

drop table #0Test 
  • 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-26T17:23:49+00:00Added an answer on May 26, 2026 at 5:23 pm

    The behavior you see is the one describe din the product documentation. The rules of Data Type Precedence specify that int has higher precedence than nvarchar therefore the operation has to occur as an int type:

    When an operator combines two expressions of different data types, the
    rules for data type precedence specify that the data type with the
    lower precedence is converted to the data type with the higher
    precedence

    Therefore your query is actually as follow:

    Select *
    from #0Test
    Where cast(test as int) = 0;
    

    and the empty string N'' yields the value 0 when cast to int:

    select cast(N'' as int)
    
    -----------
    0
    
    (1 row(s) affected)
    

    Therefore the expected result is the one you see, the rows with an empty string qualify for the predicate test = 0. Further proof that you should never mix types freely. For a more detailed discussion of the topic, see How Data Access Code Affects Database Performance.

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

Sidebar

Related Questions

I.E. Does full text search work just as well/better searching through only integers separated
After searching extensively for a function that would convert integers into visually equivalent strings
Searching for values that uses the same value Example SELECT Name, UnitPrice, Quantity, Color
Searching here I found that this question was already asked , but I think
Searching from google.com, like www.abc.com Search Result Rank the pages like Title..... Description... www.abc.com
I just ran into a problem. I know these integers, $integers : 3,5,15,20. I
I'm looking for some help. I've tried searching this site and have tried amending
I started using JNI to call Java classes from C++ some weeks ago and
I am searching a grid view using control parameters, but in my code I
I have a system that generates values in a text file which contains values

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.