|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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? |
|
#3
|
|||
|
|||
|
ahhh, dang it, you're dealing w/the entire string aren't you? Sorry man, thought you were dealing w/individual rows.
|
|
#4
|
|||
|
|||
|
Quote:
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. |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Help with a query for Parsing data in a string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|