MySqlTalk.com  

Go Back   MySqlTalk.com > MySQL > Database Design
User Name
Password
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread
Old 11-17-2004, 03:28 PM   #1
kfschaefer
Junior Member
 
Join Date: Nov 2004
Posts: 2 kfschaefer is on a distinguished road
Thumbs down Limiting Data to specific format

I am updating a table from text document - I need to limit the data to only those records that met a certain format criteria. (####-###)

My field for ProjectNum currently contains mixed data -

example:

2787
116202
119002
140302
154402
155902
157602
4714001
5157001
5739001
6249001
6335001
00000-000
00000-001
00001-001
00001-002
00001-005
00001-011
00002-001
00002-002
CADFileList
CADFileList
CINCINNAT
filelist
filelist
NULL
nzweob
Shortcut (2) to Forecast
Shortcut to Forecast
SLCT1F
STARBUCKS
TEST
TESTX



The only data I want in my table is the correct ProjectNum = 00002-002.

How do I insure that my data meets this criteria (####-###)

Here is my current query - feel free to make changes accordingly.

Karen

SELECT Q1.ProjectNum,
CURRENT_TIMESTAMP AS DateCreated,
'Import' AS UserCreated,
Q1.DateModified,
'Import' AS UserModified
FROM
(
SELECT Cast(Col004 as varchar(9)) AS ProjectNum, Cast(Col008 as datetime) AS DateModified
FROM CADFileList
WHERE (Col004 IS NOT NULL) OR
(Col004 LIKE '[0-9][0-9][0-9][0-9][0-9][-][0-9][0-9][0-9]%)') or Len(Col004)=9
) Q1
LEFT OUTER JOIN ProjectDemand ON Q1.ProjectNum = ProjectDemand.ProjectNumber
WHERE (ProjectDemand.ProjectNumber IS NULL) OR
(ProjectNum LIKE N'[0-9][0-9][0-9][0-9][0-9][-][0-9][0-9][0-9]%)' or Len(ProjectNum)=9)
kfschaefer is offline   Fork this post Reply With Quote
Old 11-18-2004, 02:48 AM   #2
codenode
Member
 
Join Date: Nov 2004
Posts: 31 codenode is on a distinguished road
Re: Limiting Data to specific format

Instead of LIKE you need REGEXP. And to get a pattern exactly ####-###
and nothing more the regex pattern would be:
^[0-9][0-9][0-9][0-9]\-[0-9][0-9][0-9]$
codenode is offline   Fork this post Reply With Quote
Old 12-01-2004, 05:05 AM   #3
Vmusic
Junior Member
 
Join Date: Dec 2004
Posts: 11 Vmusic is on a distinguished road
Re: Limiting Data to specific format

Karen,
Since this is a design forum, I thought I'd say from a design perspective... I smell trouble.

You stated your column should only have data in a format '##-###' (not certain I have the correct number of characters here)

This looks like a 'concatenated' data element. OoOOOOHHHhhh Karen, please please please don't do that... That will I promise come back to bite you.

If the first two characters of your data element represent something, give that something its own column. For example if the first two characters were state, then make state (i'm refering to geographical state here) its own column in this table.

What if you have to search or sort by 'part' of this data element?
How many lines of code are you going to write to separate these out, when placing each part of this data into its own column does that for you.

Good Luck!!!!
Vmusic
Vmusic is offline   Fork this post Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Corruption using navicat webie Navicat Support 1 08-19-2005 02:12 PM
How do you validate data that is in comma delimeted format? Azkaban SQL syntax 5 01-18-2005 06:00 AM
Import Access, Excel and data of other formats to MySQL by Navicat NavicatGuy Articles 0 08-17-2004 01:08 AM
3.3 Creating and Using a Database Administrator Documentation 13 06-09-2004 04:56 PM
2 Installing MySQL Administrator Documentation 103 06-09-2004 02:53 AM



All times are GMT -4. The time now is 01:21 PM.



Powered by: vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Google
  Web http://www.mysqltalk.com
DISCLAIMERS:
1. We have no commercial interest in this site.
Banner Ads and Subscriptions will only be used to help pay for hosting and maintenance costs.
2. MySQLTalk.com is NOT affiliated with MySQL AB in any way.
3. MySQLTalk.com is NOT endorsed by MySQL AB in any way.
4. Please do not post any content that is harmful to MySQL or MySQL AB, meaning no misleading or obsolete information will be tolerated.
Well-founded constructive criticism meant to help the community is permitted.
5. This website is founded with the goal of improving the MySQL community.
We not only tolerate newbies, we encourage them.
Please do not ask newbies to "read the manual".