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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:39:22+00:00 2026-05-24T01:39:22+00:00

I have a LINQ-to-SQL query, and I order on an nvarchar field called CustomerReference.

  • 0

I have a LINQ-to-SQL query, and I order on an nvarchar field called CustomerReference. The problem is, reference’s that start with a capital letter seem to be after ones without capitals, when I need this the other way around. For example, if I have the following rows:

d93838
D98484

It is currently ordered in that sequence right now, however I need it reversed – so it’d be like this

D98484
d93838

Any ideas guys? 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-24T01:39:23+00:00Added an answer on May 24, 2026 at 1:39 am

    This assumes the Format [A-Za-z]\d+ and will put b3432 before C1234 but after B9999

    list.OrderBy (l => l.CustomerReference.Substring(0,1).ToLower())
        .ThenByDescending(l =>l.CustomerReference.Substring(0,1).ToUpper()==l.CustomerReference.Substring(0,1))
        .ThenBy (l =>l.CustomerReference )
    

    EDIT: I was asked for the SQL too so this is what LINQPad does

    -- Region Parameters
    DECLARE @p0 Int SET @p0 = 0
    DECLARE @p1 Int SET @p1 = 1
    DECLARE @p2 Int SET @p2 = 0
    DECLARE @p3 Int SET @p3 = 1
    DECLARE @p4 Int SET @p4 = 0
    DECLARE @p5 Int SET @p5 = 1
    -- EndRegion
    SELECT [T0].CustomerReference FROM [dbo].[test] AS [t0]
    ORDER BY LOWER(SUBSTRING([t0].[CustomerReference], @p0 + 1, @p1)), 
    (CASE 
        WHEN UPPER(SUBSTRING([t0].[CustomerReference], @p2 + 1, @p3)) = SUBSTRING([t0].[CustomerReference], @p4 + 1, @p5) THEN 1
        WHEN NOT (UPPER(SUBSTRING([t0].[CustomerReference], @p2 + 1, @p3)) = SUBSTRING([t0].[CustomerReference], @p4 + 1, @p5)) THEN 0
        ELSE NULL
     END) DESC, [t0].[CustomerReference]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Linq to SQL query that was working just fine with SQL
I have a linq-to-sql query over entity that has child entityset that I need
I've installed Linq To Sql Profiler and notice, that i have double query executing
Strange performance outcome, I have a LINQ to SQL query which uses several let
I have the following Linq to SQL query, in which I'm trying to do
I have a very simple linq to sql query in C#: int acctNum =
I have a DataGridView bound to a LINQ to SQL query expression. I want
I have a LINQ-to-SQL DataContext that represents a parent-child relationship of Products to Prices.
I have a reasonably long SQL query that I need to run in a
I am working with a LINQ to SQL query and have run into an

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.