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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:46:53+00:00 2026-06-12T09:46:53+00:00

I have a SQL 2008 database with a table having a field ‘Category’ of

  • 0

I have a SQL 2008 database with a table having a field ‘Category’ of type nvarchar, which has values such as :

A1
A10
A2
B1/1
B1/2
B1/3
D1(1)
D1(2)

etc.

I know this is not good structure for the data, but we now need to somehow narrow down searches to this table such that the user will enter a start and end category (i.e. A1 to A15, or B1/1 to B/3) and we want to only return records with these category values.

Is there a way this can be done? The other thing is that we would also like to have the results sorted correctly (ie. A10 after A2).

c.

  • 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-12T09:46:54+00:00Added an answer on June 12, 2026 at 9:46 am

    You can narrow down the return result using WHERE clauses. For example:

    SELECT  Col1
           ,Col2
           ...
           ,Coln
    FROM SourceTable
    WHERE Col1>'A1' AND Col1<'A15' 
    

    You can use this values (‘A1’ and ‘A15’) as input parameters of user defined function. Then it will be very easy to pass ‘B1’ and ‘B15’ or everything else instead them.

    Also, if you want to display ‘A10’ after ‘A2’

    For more information about user defined functions – User Defined functions

    Check this information for strings compression in T-SQL. Also you should spend some time on collisions – are you comparing strings case sensitive or case insensitive.

    As to “The other thing is that we would also like to have the results sorted correctly (ie. A10 after A2)” you can add some logic in your function like this:

    DECLARE @ParamOne NVARCHAR(2)='A2'
    DECLARE @ParamTwo NVARCHAR(3)='A10'
    
    SELECT  CASE WHEN LEN(@ParamOne)=2
                 THEN CASE WHEN @ParamTwo<STUFF(@ParamOne,2,0,'0')
                        THEN 1
                 ELSE 2
                 END
            ELSE
                 CASE WHEN @ParamTwo<@ParamOne
                        THEN 1
                 ELSE 2
                 END
            END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2008 database and a nvarchar(256) field of a table.
I have a simple database table (SQL Server 2008 R2 Express), which has a
I have an SQL Server 2008 database with a table that has a column
I have a database in SQL Server 2008 and one particular table has information
I have a table like this in my database (SQL Server 2008) ID Type
I have SQL Server 2008 database with 2 tables: Table A has columns ID
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have got a table in an SQL Server 2008 R2 database. It contains
On a SQL Server 2008 R2 database I have a table with a single
I have a table in SQL Server 2008 with a column having the string

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.