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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:02:47+00:00 2026-05-27T05:02:47+00:00

If I have a varchar column which has the length 30: [SpecificCode] –> varchar(30)

  • 0

If I have a varchar column which has the length 30:

[SpecificCode] –> varchar(30) in a db table called [Item]

And if I have to query this table rows to obtain all the rows which have

SpecificCode between 789 and 15000

What may be the fastest way to SELECT in TSQL? (Range test is needed on a varchar field with length 30)

SELECT *
FROM Item
WHERE Item.SepecificCode --how to filter between 789 and 15000?
  • 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-27T05:02:48+00:00Added an answer on May 27, 2026 at 5:02 am

    Assuming the column is full of non-numeric rubbish but no decimals

    SELECT *
    FROM Item
    WHERE
        RIGHT('00' + Item.SpecificCode, 5) BETWEEN '789' and '15000'
        AND
        ISNUMERIC(Item.SpecificCode) = 1;
    

    If just integers

    SELECT *
    FROM Item
    WHERE
        CAST(Item.SpecificCode AS int) BETWEEN 789 and 15000;
    

    If floats too:

    SELECT *
    FROM Item
    WHERE
        CAST(Item.SpecificCode AS float) BETWEEN 789 and 15000
        AND
        FLOOR(CAST(Item.SpecificCode AS float)) = CAST(Item.SpecificCode AS int)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which has two varchar(Max) columns Column 1 Column 2 -----------------------
I have a column which has date-values stored in varchar (format ddmmyy) like this
I have a varchar column that has data like this top<somenumber> so the word
I'm trying to query a table which has a column that contains straight xml
I have a very simple table called genre , which looks like this: GENRE
I have a table in a MySQL Database which has this structure: CREATE TABLE
I have a very typical situation. We have a table called Users which has
I have a table which has column_id of type varchar2. This table may contain
In an access table I have a column which has the Required property set
I have two tables. T1 has one column which has 9000 unique records (varchar).

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.