Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL statement

Posted on 2009-04-10
8
Medium Priority
?
272 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 2000 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

598 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