Solved

MSaccess Select identity

Posted on 2010-09-01
3
547 Views
Last Modified: 2012-05-10
Hello folks I've this statment and I need to retrieve the identity after I do an SELECT INTO. Im using UNION ALL

Thanks for any help
SELECT  IDENTITY(int, 1, 1) as aa, * 
INTO newTable
FROM (Table A
UNION ALL
TABLE B)

Open in new window

0
Comment
Question by:nkoriginal
3 Comments
 
LVL 32

Assisted Solution

by:Daniel Wilson
Daniel Wilson earned 250 total points
ID: 33577459
please try:

SELECT  @@IDENTITY as aa, * 
INTO newTable
FROM (Table A
UNION ALL
TABLE B)

Open in new window

0
 
LVL 5

Author Comment

by:nkoriginal
ID: 33577569
Thanks.!!
It's works but the column "aa" has a ZERO value.
How I can do to insert in that column (aa) an autoincrement value??

Thanks
0
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
ID: 33577920
There isn't any way to specify an autoincrement field inan Access Make-table query.
You would have to run another quer/ execute another SQL string afterwards to Alter the table and column to set the autoincrement property.

ALTER TABLE table_name ALTER COLUMN column_name Counter

Alternativley use a pre-built table which includes an autonumber field, and use delete and append queries instead.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question