January 3, 2012 at 12:12 pm
Hello,
Let's say I have 8 columns A - H in a spreadsheet. Some rows utilize all 8 columns for the address whereas others will have empty cells within their row, due to simpler addresses.
Now my question I need a query where it parses the zip code from the address lines and puts the zip in another column on its own. For my data the last address column H will contain the zip code alone or city, state and zip code at times.
For ex.
I would need it to check the last column H. See if its blank or contains data.
If it contains data check parse the zip code and place it in the new column "I".
If the last cell in column H is blank goto column G and check to see if their is data to parse and place zip code in the new zip column "I".
Please let me know if this is clear.
Thanks.
January 3, 2012 at 1:21 pm
Can you post a sample of your spreadsheet and what the desired result is from that data? It is pretty hard to figure out details of what you are doing without something to look at.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 3, 2012 at 1:50 pm
Here is the image:
Unfortunately, I was incorrect with the information. Instead of this being a spreadsheet let's say this is a table in SQLServer, but the data looks the same as in the image except that it is a table. I want to do the same parsing and add the data onto a new column after the shares column just showing the zip code.
Thanks.
January 3, 2012 at 1:59 pm
Can you post some ddl (create table scripts), sample data (insert statements)? I pretty much understand what you want out of it. Hopefully you have some consistency in your formatting (single space before the zip or something like that). If so, this should be pretty straight forward with some nullif, isnull, substring manipulation.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 3, 2012 at 2:47 pm
PLease also attached the data (or a subset of it)
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply