1

Hi guys I am not much of a coder just trying to help out our demographics team. what I need is this I need a select statement that will scan through a table and based on the number from one column put that row into a new table.

So say i have a table with the following columns Name, Address, State, ZIP. I want a select statement that will go through and get the value from state and say ok it's AZ put it into a table called AZ, and then in the next one it's CA put it into CA, and then the next one may be AZ so add it to the table AZ it already created.

I also cant tell it what the values are for the states as they are random (it's not really states that we use just using that as an example.)

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70
  • Your question is not clear ...give us some sample data and expected results. you would need something like this for SQL Server : `;WITH MatchedData AS ( -- change this as needed - just determine which rows match your criteria ! -- return all the columns necessary for the INSERT SELECT (columns) FROM dbo.SourceTable WHERE ID IN (SELECT DISTINCT ID FROM dbo.TargetTable) ) INSERT INTO dbo.ThirdTable(Col1, Col2, ....., ColN) SELECT Col1, Col2, ....., ColN FROM MatchedData` – Kin Shah Oct 04 '13 at 19:25
  • Which DBMS do you use? Postgres? Oracle? –  Oct 04 '13 at 19:25
  • Sorry I wish I could be more clear, sadly this isnt my strong point. This isnt DBMS it's a mapping program that we use. These are just table files that are open within mapinfo –  Oct 04 '13 at 19:45
  • Don't use a database for this. You are trying to "design" a database schema from the information held in your data. Process the data outside the database, create you tables and then load your data. – Tony Oct 05 '13 at 00:19

0 Answers0