Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have the following challenge. I need to search field for a specific string of text.
Then return all of the characters up to a delimiter.

This is an example of a row of data in the field. GENETABLE.GeneField

Gene ID=ABA2 SIS4 GIN1 SDR1 ISI4 SRE1 ATABA2 ATSDR1_AT1G52340 | Genotype_Zygosity=homozygous diploid _APO:0000229 | Mutant LOF_GOF ID=loss of function_APO:0000011 && Gene ID=CESA8 IRX1 ATCESA8 LEW2_AT4G18780 | Genotype_Zygosity=homozygous diploid _APO:0000229 | Mutant LOF_GOF ID=loss of function_APO:0000011

So I the specific string needed is 'Gene ID='

Then I would return one row:
Gene ID=ABA2 SIS4 GIN1 SDR1 ISI4 SRE1 ATABA2 ATSDR1_AT1G52340 |
It would find the next gene id and return another row
Gene ID=CESA8 IRX1 ATCESA8 LEW2_AT4G18780 |

So it would split out this field into 2 rows.

Desired output
Gene ID=ABA2 SIS4 GIN1 SDR1 ISI4 SRE1 ATABA2 ATSDR1_AT1G52340 |
Gene ID=CESA8 IRX1 ATCESA8 LEW2_AT4G18780 |

After this it it would move to the next row of the GENETABLE

Any help would be greatly appreciated!

Thanks
Posted
Comments
PIEBALDconsult 7-Nov-15 18:42pm    
You want a Regular Expression and therefore a CLR function that performs Regular Expressions. No big deal.

1 solution

Let me state first that this is a misuse of the relational model. Even worse the modeling process that resulted in this schema was not even aware of the non-standard features of the RDBMS it targeted. Why don't you store such name-value collections as XML? SQL Server has built-in tools for that.

If you can't change the data representation, and you have the right, the simplest approach is to implement a table valued CLR user defined function.

See:
https://msdn.microsoft.com/en-us/library/ms131103.aspx?f=255&MSPPError=-2147217396[^]
https://www.mssqltips.com/sqlservertip/2582/introduction-to-sql-server-clr-table-valued-functions/[^]

Of course, there is also t-sql solution.
You can start here: Split string into Rows / Columns using Delimiters[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900