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

The Archive Base Latest Questions

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

I’ve experienced today strange issue. One of my projects is running .NET + SQL

  • 0

I’ve experienced today strange issue. One of my projects is running .NET + SQL Server 2005 Express.
There is one query I use for some filtering.

SELECT *
  FROM [myTable]
  where UI = 2011040773395012950010370
GO

SELECT *
  FROM [myTable]
  where UI = '2011040773395012950010370'
GO

UI column is nvarchar(256) and UI value passed to filter is always 25 digits.

On my DEV environment – both queries return same row and no errors. However at my customers, after few months of running fine, first version started to return type conversion error.

Any idea why?

I’m not looking for solution – I’m looking for explanation why on one environment it works and on other doesn’t and why out of sudden it started to return errors instead of results. I’m using same tools on both (SQL Server Management Studio Express and 2 different .NET clients)

Environments are more or less the same (W2k3 + SQL Server 2005 Express)

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

    This is completely predictable and expected because of Datatype precedence

    For this, the UI column will be changed to decimal(25,0)

    where UI = 2011040773395012950010370
    

    This one is almost correct. The right hand side is varchar and is changed to nvarchar

    where UI = '2011040773395012950010370'
    

    This is the really correct version where both types are the same

    where UI = N'2011040773395012950010370'
    

    Errors will have started because the UI column now contains a value that won’t CAST to decimal(25,0).

    Some unrelated notes:

    • if you have an index on the UI column it would be ignored in the first version because of the implicit CAST required
    • do you need unicode to store numeric digits? There is a serious overhead with unicode data types in storage and performance
    • why not use char(25) or nchar(25) is values are always fixed length? Your queries use too much memory as the optimiser assumes an average length of 128 characters based on nvarchar(256)

    Edit, after comment

    Don’t assume "why does it works sometimes" when you don’t know that it does work

    Examples:

    • The value could have been deleted then added later
    • A TOP clause or SET ROWCOUNT could mean the offending value is not reached
    • The query was never run so it couldn’t fail
    • The error is silently ignored by some other code?

    Edit 2 for hopefully more clarity

    Chat

    gbn:

    When you run WHERE UI = 2011040773395012950010370, you do not know the order of row access. So if one row does have "bicycle" you may or may not hit that row.

    Random:

    So the problem may be not in the row which i was trying to access but other one with corrupted value?

    gbn

    different machines will have different order of reads based on service pack level, index and table fragmentation, number of CPUs, parallelism maybe

    correct

    and TOP even. That kind of stuff

    As Tao mentions, it’s important to understand that another unrelated can break the query even if this one is OK.

    data type precedence can cause ALL the data in that column to be converted before the where clause is evaluated

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.