I am using SQL Server 2008 and have a hashtable which contains data about postcode and its related data. If I take the count of records groupby postcode its like this
5000 HA
6000 NW
4000 S2
I would like to know is there any way of devidng the data into three separate tables.
if we running the first set of records which is HA
which will look like
Table1 Table2 Table3
1st record of HA 2nd record of HA 3rd record of HA
4th record of HA ....etc
is it possible to achieve using cursor or any suggestion?
Any help will be appreciate
Thank you
I can’t imagine any possible reason why I would do such a thing. Dividing up into 3 tables will make the data much harder to query later. But if you’re stuck with it then I would do something along the lines of this:
BUild a mapping table with three columns A, B, C. Populate the table withthe values you want to go in each table. Shoulf look simliar to this, but woudl go out the the max value you will need.
Create a temp table using row_number over (don’t forget to order by) to so that you can now tell which record is the first HA and which is the second etc. Now do 3 inserts joining on the number you generated to each column inteh mapping table. If they join to column A insert to tableA, Column B, insert totable B, colmn c insert to table c.