Regular Expressions in SQL statements for bulk column data modification
Posted on 2006-04-08
I have extracted some data from a flat file source and uploaded into a SQL Server 2005 relational table. My goal is to extract certain parts of a string in each row of a specific column, and then place those in the associated row/column location in another SQL server destination (relational table). I am wondering if using embedded regular expressions in SQL statements is the best way to achieve the bulk data modification/retrieval. Here is an example of what I am trying to accomplish:
ADV LAT LON TIME WIND PR STAT
1 17.00 -84.20 03/00Z 30 1005 TROPICAL DEPRESSION
2 17.50 -84.50 03/03Z 30 1005 TROPICAL DEPRESSION
3 18.80 -84.60 03/09Z 30 1005 TROPICAL DEPRESSION
3A 19.50 -85.00 03/12Z 30 1005 TROPICAL DEPRESSION
4 20.00 -85.30 03/15Z 35 1004 TROPICAL STORM
4A 20.60 -85.80 03/18Z 40 1002 TROPICAL STORM
5 21.10 -85.90 03/21Z 45 1002 TROPICAL STORM
In the "TIME" column, I want to extract the first two characters as a substring from every row i.e. "03" and place it in a seperate column in another table. Then extract the two characters after "/", add two zeros and then place it in another column of a certain relational table.
I have SQL Server business intelligence 2005 tools handy, so if you feel there is some easier way to accomplish the same goal by using some in built features your aware of, let me know. If not, is it technically possible to execute a single SQL statement to accomplish this. If yes, can you give me some idea of how to write this SQL statement. I am prepared to a write a C# program to accomplish this if required.