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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:39:09+00:00 2026-06-09T18:39:09+00:00

Am newbie to SQL Server. In that i need to sort the following data

  • 0

Am newbie to SQL Server. In that i need to sort the following data

1, 1AB, 1AA, 20, 3C, 4D 

into

1, 1AA, 1AB, 3C, 4D, 20.

My coding is of

IF EXISTS ( SELECT name FROM sysobjects WHERE name = 'getIntPortion')
 DROP FUNCTION getIntPortion
GO    
CREATE FUNCTION dbo.getIntPortion ( @inputVarchar varchar(255))
RETURNS VARCHAR(255)
AS
BEGIN
 WHILE(PATINDEX('%[^0-9]%', @inputVarchar) ) > 0
 BEGIN
 --then remove that one character, then continue
 SET @inputVarchar = REPLACE(@inputVarchar
 , SUBSTRING(@inputVarchar, PATINDEX('%[^0-9]%', @inputVarchar), 1)
 , '')
 END
 RETURN @inputVarchar
END

SELECT km_ph_act_chapt_no FROM [KM_DB].[dbo].[km_ph_act_chapters]
ORDER BY CONVERT(INT, dbo.getIntPortion(km_ph_act_chapt_no))

For this Alpha is not ordering… Hopefully waiting for reply.

Thanks and Regards,

Asker

  • 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-09T18:39:11+00:00Added an answer on June 9, 2026 at 6:39 pm

    Assuming your function works correctly, change the order by to

    SELECT km_ph_act_chapt_no FROM [KM_DB].[dbo].[km_ph_act_chapters] 
    ORDER BY CONVERT(INT, dbo.getIntPortion(km_ph_act_chapt_no)) ,
       km_ph_act_chapt_no
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a newbie in SQL server. I've the following table: id dayoftheweek timeoftheday 1
Dear All, please help me since I'm newbie in SQL Server. I have a
I'm brand new to SQL Server 2008, and have some newbie questions about the
I am newbie to SQL Server Express. At the moment I am manually attaching
I’m a newbie in Stored Procedures in SQL Server 2005. Let’s say we have
I am using SQL SERVER 2005 and i am also newbie to SQL SERVER
I'm a newbie for SQL Server. Please help me out with my below problem.
I am newbie in Sql Server.I am trying to attach AdventureWorks database with Sql
I am a newbie to SQL server. keeping this question as reference.My doubt is
Firstly I'm a complete newbie when it comes to SQL Server. I have five

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.