Solved

SQL statement

Posted on 2009-04-10
8
249 Views
Last Modified: 2012-05-06
Hi,

How can I create a temp table that has a primary auto increment.

CREATE TABLE #TEMPPRJ
(
      TPPrjID INT PRIMARY KEY Auto_increment,
      TPProject char(24) NULL
)
it says incorrect syntax near Auto_increment.
 
there is more stuff to this question

Open in new window

0
Comment
Question by:lulu50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24118521
Try like this:
CREATE TABLE #TEMPPRJ
(
      TPPrjID INT PRIMARY KEY IDENTITY(1,1),
      TPProject char(24) NULL
);
 
INSERT INTO #TEMPPRJ(TPProject)
SELECT 'Test'
UNION SELECT 'Another Test';
 
SELECT * FROM #TEMPPRJ;
 
DROP TABLE #TEMPPRJ;

Open in new window

0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24118545
For your reading pleasure:
http://msdn.microsoft.com/en-us/library/aa258255(SQL.80).aspx

Best regards,
Kevin
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24118573
no points please...just something else to read about besides what Kevin posted.

http://sqlservernation.com/blogs/tipweek/archive/2009/02/23/identity-columns.aspx
0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 

Author Comment

by:lulu50
ID: 24118609
How can I append data to the temp table from a select statement say customer
0
 

Author Comment

by:lulu50
ID: 24118630
select * from #TEMPPRJ

output is:

TPPrjID   TPProject
01           58695
02           58659
03           59865

now I want to append to the temp table a column with data from
customer table

select customername from customer
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24118638
Change this statement:
INSERT INTO #TEMPPRJ(TPProject)
SELECT 'Test'
UNION SELECT 'Another Test';

To something like this:
INSERT INTO #TEMPPRJ(TPProject)
SELECT DISTINCT ProjectColumnName
FROM Customer
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24118657
If you mean, you want to join on project to get the customer name then do something like this:

SELECT t.*, c.customername
FROM #TEMPPRJ t
INNER JOIN Customer c ON c.TPProject = t.TPProject

OR something to that effect.  If you meant to insert new rows of TPProject values based on customername values in your customer table, see my original suggestion using INSERT INTO.
0
 

Author Closing Comment

by:lulu50
ID: 31569031
Excellent Thank you
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 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