I have a spreadsheet with many columns, one of which is the owner_id column. The problem is that this column contains a comma-delimited list of owner IDs and not just one.
I have imported this spreadsheet into my SQL database (2008) and completed other importing tasks and now a parcel_id column as the result of this process.
I need to make an entry in my parcelholder table for each parcelID / ownerID couple, but I'm not sure how to go about commas with the owner ID Is in the delimited list.
My tables look like this:
ImportData ============= ==== Owner / varchar, parceledet sample line ( Owner_id = '13782, 21431', parcel id = 319) Parcelonoizers ================ Owner IDE int, the parcelidined row table with import data should look like this: Owner ID = 13782, Pascaled = 319 owner id = 21431, parsedle = 319 Is this a common condition for anyone, and if so, how do you get about this?
At the following function you will split comma-seep columns into a table. Then repeat you through the temporary table and use the data from your single column to insert 1 row into your parceloiner table. To get this to work, you will need an internal loop to repeat the outer line through the parcelholder table and @ qualified for each line. Also, do not forget, if you do not come into a line in your outer loop, there is no comma in the owner_id column, then you do not want to do anything. Returns the Returnable Tab (Item Worker (8000)) as FUNCTION dbo.Split (@ string varchar (8000), @ delimiter four (1)), as declared @idx int Please @ slice varchar (8000) Announce @idx = 1 Select Len (@string) & lt; 1 or @ string is an empty return while @idx! = 0 is set @idx = charindex (@elimiter, @ string) if @idx! = 0 set @slice = left (@ string, @ idx - 1) Other set @slice = @ string if (lane (@ slice)> 0) set @temptable (item) values (@ slices) @ string = Wright (@ string, lane (string @) - set @edex) if lane (@ string) = 0 break and return end
Comments
Post a Comment