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

  • Home
  • SEARCH
  • 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 6388621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:18:07+00:00 2026-05-25T03:18:07+00:00

We’re currently testing our app from SQL Server 2000 to 2008R2. The following statement

  • 0

We’re currently testing our app from SQL Server 2000 to 2008R2.

The following statement works in 2000, and not in 2008.

select distinct left(tz.Zipcode,5) as zipCode
from TerritoryZip tz 
order by tz.Zipcode

The error message is:

Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

The fix is simple:

select distinct left(tz.Zipcode,5) as zipCode
from TerritoryZip tz 
order by left(tz.Zipcode,5)

However there is a risk that we may not find all the instances of this type of SQL.

So one solution might be to set the compatibility level to 2000 – what are the cons of doing that (e.g. performance of not updating the SQL to use this more strict approach)?

And are there other options/settings, e.g. is there a ‘strictness’ setting that is enforcing better practices, etc…?

Thanks!!

  • 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-25T03:18:07+00:00Added an answer on May 25, 2026 at 3:18 am

    You could change the semantics slightly by doing this:

    SELECT ZipCode FROM 
    (
      SELECT DISTINCT ZipCode = LEFT(tz.Zipcode, 5)
        FROM dbo.TerritoryZip
    ) AS x
    ORDER BY ZipCode;
    

    Doesn’t solve the problem really since the query is more verbose and you still can’t avoid touching it. The fix you’ve already suggested is better in my mind because it is more explicit about what is going on.

    Not to be harsh, but if you don’t think you’ll be able to “find all the instances of this type of SQL” then how are you trusting your testing at all?

    I would suggest that keeping 2000 mode is not the optimal answer. The reason is this can cause other syntax to break (e.g. the way you might call dynamic management functions – see this Paul Randal blog post and my comment to it), you also run the risk of perpetuating code that should be fixed (e.g. old-style *= / =* joins that are valid in 2000 compat mode, but won’t be valid when you go from 2008 R2 -> Denali, which doesn’t support 2000 compat).

    There is no “strictness” setting but you can vote for Erland Sommarskog’s SET STRICT_CHECKS ON; suggestion.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT

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.