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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:20:31+00:00 2026-06-12T07:20:31+00:00

I have SQL server 2008 R2, windows 7 OS. Within the server, I have

  • 0

I have SQL server 2008 R2, windows 7 OS.

Within the server, I have a table con1 which was created by following SQL statement.

CREATE TABLE [dbo].[con1](
    [digit_str] [nvarchar](50) NULL
) ON [PRIMARY]

In the con1 table, I have these values:

 digit_str
----------------
    1
    1
    2
    3
    4
    5
    1.

I did executed following SQL statement against the database:

SELECT t1.digit FROM
(
select CAST(digit_str as int) as digit from con1 where RIGHT(digit_str,1) <> '.'
) as t1
where t1.digit <> 1

the server given me following error message:

Conversion failed when converting the nvarchar value ‘1.’ to data type int.

I thought my inner SQL executed first and created a temp table t1, so 1. is not included in table t1, then SQL parser will use where t1.digit <> 1 to filter temp table t1.

But above seems not right, so any one explains execution order of above SQL?

  • 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-12T07:20:32+00:00Added an answer on June 12, 2026 at 7:20 am

    This is a known “feature” of SQL Server. Don’t ever assume that the WHERE clause executes before the SELECT clause.

    See: SQL Server should not raise illogical errors

    There are actually good reasons for doing that sometimes. Consider joining two tables, with A being much smaller than B.

    select CAST(A.col1 as int), A.col2, B.col3
    from A join B ...
    where ... isnumeric(A.col1) = 1
    

    If you inspect the query plan generated, rightly or wrongly, SQL server will stream the data from A as the leading rows to join against B. While doing that, it knows that it only needs to pull col2 and function on col1. It could bring col1 through just to run the function later, or for something as trivial as CAST, SQL Server might as well transform the data during the streaming process.

    One thing’s for sure, this strategy does make SQL Server one little bit faster in certain queries. But on a purely logical perspective, I would call it a bug.

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

Sidebar

Related Questions

I have installed SQL Server 2008 R2 Express on Windows 7. When I run
I have just installed SQL Server 2008 including Reporting Services on Windows Server 2003.
I have configured Service Broker communication between two SQL Server 2008 instances using Windows
I have 1 PC (Windows Server 2003 + SQL Server 2008) and 2 PCs
I have SQL Server 2008 with a table called ProductCategories designed like this: Id
I have a website running on a Windows 2008 R2 server, using a SQL
I have installed SQL Server 2008 R2 Express on a Windows Server 2008 R2
I have SQL Server 2005 installed and VS 2008 on Windows XP Pro SP2.
I have SQL Server 2008 installed on Windows 2008 Server. I've disabled built-in administrator
I have set up SQL Server 2008 R2 on a Windows Server 2008 machine

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.