473,382 Members | 1,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Validating records in a table

3
Hi I have a file with the following entities loaded in a temp table

idno
Caseno
passport no

Now I need to validate that this records are avalaible before going to the marching of this values in my temp table with my main table. How do I validate this records in my Temp Table. There are lots of records in the table so I think I will need a cursor. I am new to Sql. Someone pls help me asap
Feb 9 '10 #1
1 1001
nbiswas
149 100+
Hi, the question is not very clear. Reason

a) What is a valid IdNo? Is it Integer, String/Varchar, Alphanumeric and also of any specified length ... exactly what?

b) The same is applicable for case number too.....

c) Passport number varies across countries. So it is difficult to validate a passport number. Screening can be done through World-Check or a number of other organizations:http://www.world-check.com/en-US/Ser...es/Online.aspx

However, I am first going to give you some case by case sample and then will take you with a larger scenario.

Validation for Id Numbers/ Case Numbers

Case 1 (Assuming only integers and maximum length is 3)

e.g. 001 is a valid Id but neither 01 or A12 or AAA

Expand|Select|Wrap|Line Numbers
  1. Select Id from tblSample where Id like REPLACE('XXX','X','[0-9]')
Case 2 (Assuming only Strings and maximum length is 3)

e.g. AAA is a valid Id but neither 01 or A12 or 001

Expand|Select|Wrap|Line Numbers
  1. Select Id from tblSample where Id like REPLACE('XXX','X','[A-Z]')
Case 3 (Assuming only alphanumerics and maximum length is 3)

e.g. AA2 is a valid Id but neither 01 or 001

Expand|Select|Wrap|Line Numbers
  1. Select Id from tblSample where Id like REPLACE('XXX','X','[A-Z][0-9]')
Case 4 (Assuming a format of xxx-xx-xxx where x is alphanumeric and maximum length is 8)

e.g. AA2 is a valid Id but neither 01 or 001

Expand|Select|Wrap|Line Numbers
  1. Select Id from tblSample where Id like REPLACE('xxx-xx-xxx','x','[A-Z][0-9]')
Validation for Indian Passport

A typical Indian passport number is : X1234567

i.e.
- Total length = 8
- Alphanumeric
-First Character is ALPHABET
-Last 7 characters are NUMERICS

Query is

Expand|Select|Wrap|Line Numbers
  1. Select Passport from tblSample where Passport
  2. LIKE '[A-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
Now take a SampleTable(say tblInfos) whose structure is as under

Expand|Select|Wrap|Line Numbers
  1.  ID         CaseNumber        PassportNumber
  2.  
  3.   001       100                      X1234567
  4.  
  5.   002       101                      ABCDEFRT78
  6.  
  7.   00A       101                     X1234568
  8.  
  9.   003        XYZ                     P1234567
  10.  
  11.   004       102                      V0987654
Query

Expand|Select|Wrap|Line Numbers
  1. Select ID,CaseNumber,PassportNumber From tblInfos
  2. Where 
  3.  
  4. Id                            LIKE REPLACE('XXX','X','[0-9]')      AND
  5. CaseNumber            LIKE REPLACE('XXX','X','[0-9]')      AND
  6. PassportNumber      LIKE '[A-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
Output:
Expand|Select|Wrap|Line Numbers
  1. ID         CaseNumber        PassportNumber
  2.  
  3.   001       100                      X1234567  
  4.   004       102                      V0987654
Rules applied for validation are:

- Id/Case Number should be 3 digit numbers

- Valid Indian passport.


Hope this helps.

Now I think with this idea, you can go ahead and implement the same in your project.
All the best.
Mar 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Eranut | last post by:
Hi, I am trying to understand if there is a way to send a table of records (table of structs) from pro C to Oracle pl/sql stored procedure. Since Oracle is demanding definition of the *sent*...
9
by: paul | last post by:
Hiya everyone, I have two tables in SQL 2000. I would like to append the contents of TableA to TableB. Table A has around 1.1 Million Records. Table B has around 1 Million Reocords. ...
5
by: Alex | last post by:
Hi, I have two tables , A and B where table B has a foreign key constraint to table A. I want to delete all records in table A that are older than a certain date that are not referenced by...
2
by: Jason | last post by:
I have a table of 650,000 records associated to contracts. Some of the contracts have multiple records but each contract only has one Active Record (there might be several inactive records). ...
6
by: John | last post by:
I've got a single table I need to query to return records that have no "related records." Table dataset example: 1. John, Biology 2. Dave, Math 3. Susan, Biology 4. Betty, Sociology The...
9
by: Dennis Gearon | last post by:
I am designing something that may be the size of yahoo, google, ebay, etc. Just ONE many to many table could possibly have the following characteristics: 3,600,000,000 records each record is...
1
by: apprenticewizard | last post by:
Please help....been at this for several days and just can't seem to find a solution. I've got two tables, Emp Info and Labor Records. The form to populate the Labor Records table contains a combo box...
10
by: jambonjamasb | last post by:
Hi all, I am new to this and am looking for some direction I have the ideas, but am having trouble putting it into practice. Any help would be greatly appreciated. I have set up three tables. ...
3
by: Banky | last post by:
Hi I have a file with the following entities loaded in a temp table idno Caseno passport no Now I need to validate that this records are avalaible before going to the marching of this values...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.