Solved

how to get all the records with 8-digit numbers

Posted on 2011-03-14
3
473 Views
Last Modified: 2013-11-10
Hi, Experts,

In my parts table there is a part_no field with mostly 8-digit numbers but some are text mixed. In VFP, I can easily use the following command to get all records with 8-digits part numbers:

SELECT * FROM t_parts WHERE BETWEEN(VAL(part_no), 10000000,  99999999) AND LEN(ALLTRIM(part_no))=8

But in SQL with the following command, I got an error saying "conversion failed when converting teh nvarchar value '110343BC' to data type int."

SELECT * FROM t_parts WHERE CONVERT(INT, part_no) BETWEEN 10000000 AND 99999999 AND LEN(part_no)=8  

Can you tell me how to get all the records with 8-digit numbers in this situation? Tags:
0
Comment
Question by:Castlewood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 35131891
SELECT *
FROM t_parts
WHERE part_no LIKE '[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
0
 

Author Comment

by:Castlewood
ID: 35132697
Thank you for the prompt reply. That works.
Can you also tell me why the table name with a $ in the end after I imported an Excel table to SQL? For example, the table name is something like tmp_part$.
Thanks.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 35132752
By default, when you use the SQL Server import/export wizard to import from Excel, SQL Server appends a $ to the worksheet name when forming the table name.  I have no idea why that default was chosen.

You can override that if you wish.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question