Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jfieck
Starting Member
6 Posts |
Posted - 2005-06-02 : 19:44:51
|
| I am working on trying to write a SQL statement in a MS Access 2000 query that will create and populate a new table with all the records returned by another query. The catch is that I need the new table to uniquely identify each record. The old table doesn't have unique identifiers on it's records. The syntax on this is killing me.Psuedo scenario:If I had a query called 'getData' that returned this tableFIRSTNAME LASTNAMEJohn DoJane DoCan I do something like:create table #temptable( uniqueid , getData )and now have a table called #temptable that would look like this:ID FIRSTNAME LASTNAME1 John Do2 John Do?? Please help if you can. Thanks. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-06-02 : 20:00:03
|
| You can use the IDENTITY function to do this via SELECT INTO.SELECT IDENTITY(1, 1, int) AS NewTableID, FIRSTNAME, LASTNAMEINTO NewTableFROM Table1WHERE...Another way:CREATE TABLE NewTable (NewTableID int IDENTITY(1, 1), FIRSTNAME nvarchar(256), LASTNAME nvarchar(256))INSERT INTO NewTable (FIRSTNAME, LASTNAME)SELECT FIRSTNAME, LASTNAMEFROM Table1WHERE...Tara |
 |
|
|
|
|
|