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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:41:44+00:00 2026-06-08T20:41:44+00:00

I have a field which contains a string of numbers 2002 2005 2001 2006

  • 0

I have a field which contains a string of numbers

 "2002 2005 2001 2006 2008 2344"

It is preferred that we assume the spaces are the splits, else failing that, that they are 4 characters long each.

I can select a substring:

SELECT substr(years,1,4)  FROM TABLE 

But have no idea how to check each one. I am trying to find the row that contains the number closest to 0.

and I can ORDER BY and LIMIT 1.

  • 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-08T20:41:46+00:00Added an answer on June 8, 2026 at 8:41 pm

    This looks UGLY but it selects all you need in one SQLlite statement. Also you can do some optimization if assume dates are in the current interval say 1900..2100. In this case you can cut first 2 selects B,C (B: 1 union 2) (C: 9 union 0 union 1)

     select years2,years from 
        (
        select i1||i2||i3||i4  as years2 from (select '0' as i1 
                       union all 
                       select '1' as i1
                       union all 
                       select '2' as i1
                       union all 
                       select '3' as i1
                       union all 
                       select '4' as i1 
                       union all 
                       select '5' as i1 
                       union all 
                       select '6' as i1
                       union all 
                       select '7' as i1
                       union all 
                       select '8' as i1
                       union all 
                       select '9' as i1) B, 
        (select '0' as i2 
                       union all 
                       select '1' as i2
                       union all 
                       select '2' as i2
                       union all 
                       select '3' as i2
                       union all 
                       select '4' as i2 
                       union all 
                       select '5' as i2 
                       union all 
                       select '6' as i2
                       union all 
                       select '7' as i2
                       union all 
                       select '8' as i2
                       union all 
                       select '9' as i2) C,
        (select '0' as i3 
                       union all 
                       select '1' as i3
                       union all 
                       select '2' as i3
                       union all 
                       select '3' as i3
                       union all 
                       select '4' as i3 
                       union all 
                       select '5' as i3 
                       union all 
                       select '6' as i3
                       union all 
                       select '7' as i3
                       union all 
                       select '8' as i3
                       union all 
                       select '9' as i3) D,
                      (select '0' as i4 
                       union all 
                       select '1' as i4
                       union all 
                       select '2' as i4
                       union all 
                       select '3' as i4 
                       union all 
                       select '4' as i4 
                       union all 
                       select '5' as i4 
                       union all 
                       select '6' as i4
                       union all 
                       select '7' as i4
                       union all 
                       select '8' as i4
                       union all 
                       select '9' as i4) E
        ) YearsAll
    
       left join YearsTable on (YearsTable.years like '%'||YearsAll.years2||'%')
    
        where YearsTable.years is not null
    
        order by years2 limit 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a field which is varchar and contains numbers and dates as strings.
I have a field in a table which contains bitwise flags. Let's say for
I have a Car object which contains a latitude field and a longitude field.
I have a grid view which contains a button in a template field. I
i have a nvarchar(max) field named PublishTime, which contains the time in HH:MMtt (10:20AM),
i have table called as Support, which have a field named Name and contains
I have a table tblInvestigators which contains a lookup field to display a list
I have a string column which contains some numeric fields, but a lot are
Scenario: In the database I have a field called Categories which of type 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.