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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:27:58+00:00 2026-05-31T04:27:58+00:00

I have here sample table with three fields. TableA FieldA FieldB FieldC ====================================== 123XYZ456

  • 0

I have here sample table with three fields.

TableA

    FieldA        FieldB        FieldC
    ======================================
    123XYZ456     XYZ           John
    124NNN333     NNN           Jenny
    232XPT124     XPT           Jade
    456XXX345     XXX           James

FieldA has a fixedlength of 9. I didn’t design this table and some applications are already using it.

I want to select FieldB and FieldC with conditions against FieldA.

Using this sql statement:

SELECT FieldB, 
       FieldC
FROM   TableA
WHERE  FieldA LIKE Concat(@paramA, '%', @paramB) 

I cannot achieve my desired result. When I try to search with paramA value of 12 and paramB value of '', I get the 2 results:

    FieldA        FieldB        FieldC
    ======================================
    123XXX456     XXX           John
    124XXX333     XXX           Jenny

because obviously it matches with 12% and that is not what I want. I want that the params should match the correct index of the string.

If I search for paramA = '12' and paramB = '' then it should have no result. To get the fields (FieldB, FieldC), I need the correct values of paramA = '123' and paramB = '456' so it will return XYZ and John. If I want to return James then i have to give paramA = '456' and paramB = '345'

How could I correctly build a SQL Statement for this? Any idea? 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-05-31T04:27:59+00:00Added an answer on May 31, 2026 at 4:27 am

    Use LEFT() and RIGHT():

    SELECT FieldB, FieldC
    FROM   TableA
    WHERE  LEFT(FieldA,3) = @paramA 
           AND RIGHT(FieldA,3) = @paramB;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the sample data for test table I have [childId] [parentId] [present] 1
here is a simple problem. I have a table of 500 rows and what
I have a bare-bones sample project here: http://dl.dropbox.com/u/7834263/ExpandingCells.zip In this project, a UITableView has
I have built a simple menu in jQuery http://vanquish.websitewelcome.com/~toberua/ Here is a sample of
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which
So I have a work order table with 3 fields relevant to the question
I have the following sample XML: <?xml version=1.0 encoding=utf-8 ?> <queryableData> <table displayName=Shipments dbName=Quotes>
I have a MySQL (5.1.49) table with three columns. mysql> create table testme(id int
I have to be missing something simple here but it escapes me. After the
I hope I am not missing something very simple here. I have done a

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.