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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:32:06+00:00 2026-05-22T18:32:06+00:00

Does SQL Server 2008 have a string comparison method that checks which string is

  • 0

Does SQL Server 2008 have a string comparison method that checks which string is supposed to come first (ex ‘abc’ comes before ‘abd’ etc)? I need to do a <= comparison.

  • 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-22T18:32:07+00:00Added an answer on May 22, 2026 at 6:32 pm

    <= works fine. The problem you’re having is that you’re expecting numeric sorting out of strings. That doesn’t work without special handling.

    String Sorting

    a1 – a10 strings sort in this order:

    a1
    a10
    a2
    a3
    a4
    ...
    

    This is because both a1 and a10 start with “a1”.

    Since they’re strings the numeric values are irrelevant. Look what happens when we substitute a-z for 0-9:

    ab
    aba
    ac
    ad
    ae
    

    Can you see now why you’re getting the results you are? In a dictionary, aba comes before ac, and a10 comes before a2.

    To solve your problem it’s best to split your column into two: one char and one a number. Some unpleasant expressions can get the right sort order for you, but it’s a much worse solution unless you have absolutely no choice.

    Here’s one way. It may not suit or there may be a more efficient way, but I don’t know what all your data is like.

    SELECT
    FROM Table
    WHERE
       Col LIKE 'a%'
       AND Substring(Col, Convert(int, PatIndex('%[^a-z]%', Col + '0'), 1000)) <= 10
    

    If the alpha part is always one character you can do it more simply. If the numbers can have letters after them then more twiddling is needed.

    You could also try a derived table that splits the column into its separate alpha and numeric parts, then put conditions in the outer query.

    Collation

    Be aware each string and char-based column has a collation setting that determines what letters are sorted together (mostly for case and accents) and this can change the results of an inequality operation.

    SELECT *
    FROM Table
    WHERE Value <= 'abc'
    
    SELECT CASE WHEN Value <= 'abc' COLLATE Latin1_General_CS_AS_KS_WS THEN 1 ELSE 0 END
    FROM Table
    

    The collation I used there is case sensitive, accent sensitive.

    You can see all the collations available to you like so:

    SELECT *
    FROM ::fn_helpcollations()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL Server (2005/2008) Each of the below statements have the same result. Does anyone
Does SQL Server 2008 ship with the .NET 3.5 CLR, so that stored procedures
Does SQL Server 2008 have a built in debugger? I've got a stored procedure
I am using SQL Server 2008. I have tables on which there are duplicate
Using SQL Server 2008, I have a requirement that email addresses in my user
I have created a complex sql server 2008/coldfusion search page, that searches thru a
Is the Sql Server 2008 control available for download? Does it yet support the
Does anyone know the query the last synchronization date from sql server (2008). It
Does anyone have a definitive answer to whether Sql Server Management Objects is compatible
For primary keys on a large SQL Server 2008 data table, I have the

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.