![]() |
|
|
#1 |
|
Junior Member
Join Date: Nov 2004
Posts: 2
|
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) |
|
|
|
|
|
#2 |
|
Member
Join Date: Nov 2004
Posts: 31
|
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]$ |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Dec 2004
Posts: 11
|
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 |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
|
|
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 |