We help IT Professionals succeed at work.

Select query help needed

JMO9966
JMO9966 asked
on
241 Views
Last Modified: 2010-03-20
I have a field that I query that is a Text field that stores three value all of which will either be a zero or a one.

111
101
010
001
100

You get the idea.  I need to write a MSAccess and a SQL query to return any records that have the second value set to a 1.  In the example above, this would return two records (the first and third records listed).

Can someone give me a hand on the syntax for this query in MS Access and SQL?

Thanks,
JMO9966
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
SELECT *
FROM YourTable
WHERE YourField LIKE "*1*
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Need a closing quote:
SELECT *
FROM YourTable
WHERE YourField LIKE "*1*"


select <column_name> from <table_name> where substring(<column_name>, 2, 1) = 1
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
AneeshDatabase Consultant
CERTIFIED EXPERT
Top Expert 2009

Commented:
Hello JMO9966,

SELECT *
FROM YourTable
WHERE YourField LIKE '_1%'



Aneesh R
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
>stores three value
True... I'm assuming that the field length is exactly three characters, where the * would work.  If it is longer and a test for numeric characters is needed, this could be used too:

 WHERE YourField LIKE "#1#"

I'm also assuming that the back-end is Access.
CERTIFIED EXPERT

Commented:
I don't know if your field is numeric or alphanumeric but the query will work either way. For MS-SQL will be:

SELECT
      *
FROM
      YourTable
WHERE
      substring(cast(YourFiled AS varchar),2,1)='1'

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.