MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 9th, 2004, 01:12 PM
danielnwa danielnwa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 23 danielnwa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 5 sec
Reputation Power: 0
Help with a query for Parsing data in a string

Hi all,

I have a string of data that looks something like this

GA1234567889 , LI93jdf9das.... Zjd9ejs0ss;GAjdisn3932***GA3nie9d;s9

and I would like to extract all the GA plus the next 11 characters out of the string.

As you can see, there isn't a common delimitor between the GA so I have came up with a query to extract the first GA occurence in the string. What I would like to know is how to continue this search for the next occurences of GA in the string. There are no guarantee number of occurences of GA in a given string so I am hoping for some help with the possibility of a loop? Thanks for any help

SELECT SUBSTRING(LotID, POSITION('GA' IN lotID), 11) as newGALot FROM dbname

Reply With Quote
  #2  
Old May 9th, 2004, 03:13 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
This attempt is definitely open to ridicule.

If the "GA" is always on the far left, why not select Left( fieldName, 13)?? If I remember correctly, if there are less than 13 total characters (2 for "GA" plus the 11 you're looking for) then it just prints what the string has...
Code:
select  left(LotID, 13) as newGALot
from    dbname
where   LotID like 'GA%'

is that somewhat what you're looking for?

Reply With Quote
  #3  
Old May 9th, 2004, 03:15 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
ahhh, dang it, you're dealing w/the entire string aren't you? Sorry man, thought you were dealing w/individual rows.

Reply With Quote
  #4  
Old May 11th, 2004, 03:18 AM
Zveroa Zveroa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 6 Zveroa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Username=NULL
ahhh, dang it, you're dealing w/the entire string aren't you? Sorry man, thought you were dealing w/individual rows.


Agree. Daniel must either handle this row-based and parse the string while SELECTing. Another solution will be to change the database structure and pick the GAs before INSERTing them. One GA for each row should do the trick. But If changing the database model isn't an option, this GA-parsing must be done by handle each row.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Help with a query for Parsing data in a string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT