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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:26:50+00:00 2026-06-06T00:26:50+00:00

I have a scalar value function that returns a varchar of data containing the

  • 0

I have a scalar value function that returns a varchar of data containing the ASCII unit seperator Char(31). I am using this result as part of an Order By clause and attempting to sort in ascending order.

My scalar value function returns results like the following (nonprintable character spelled out for reference)

  • ABC
  • ABC (CHAR(31)) DEF
  • ABC (CHAR(31)) DEF (CHAR(31)) HIJ

I would expect that when I order by ascending the results would be the following:

  • ABC
  • ABCDEF
  • ABCDEFHIJ

instead I am seeing the results as the complete opposite:

  • ABCDEFHIJ
  • ABCDEF
  • ABC

Now I am fairly certain that this has to do with the non-printable characters, but I am not sure why. Any idea as to why that is the case?

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-06-06T00:26:51+00:00Added an answer on June 6, 2026 at 12:26 am

    The sortorder can be influenced by your COLLATION settings. Following script, explicitly using Latin1_General_CI_AS as collation orders the items as you would expect.

    ;WITH q (Col) AS (
        SELECT 'ABC' UNION ALL
        SELECT 'ABC' + CHAR(31) + 'DEF' UNION ALL
        SELECT 'ABC' + CHAR(31) + 'DEF' + CHAR(31) + 'HIJ'
    )
    SELECT  *
    FROM    q   
    ORDER BY
            Col COLLATE Latin1_General_CI_AS
    

    What collation are you using? You can verify your current database collation settings with

    SELECT DATABASEPROPERTYEX('master', 'Collation') SQLCollation;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have coded a view that relies on a scalar function value for one
We have a scalar function that returns a DateTime. It performs a couple of
I have a scalar-valued function called DATEONLY that returns DATEADD(DD,0, DATEDIFF(DD,0, @DATETIME)), just like
I have a Scalar-valued function in my DB: ALTER FUNCTION [dbo].[fx_fooFunct] (@MyParam varchar(max)) RETURNS
I have a stored procedure that returns a scalar value, I mapped it in
I have a recursive scalar function that needs to update a record in another
I have a ko.computed() function that proxies a collection like this: function ListView(query) {
Suppose I have a SQL function that returns a table and I get the
Suppose I have a SQL function that returns a table and I get the
I have a query that needs to return a scalar value if the item

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.