Solved

how to get all the records with 8-digit numbers

Posted on 2011-03-14
3
466 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now