Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2010, 03:41 AM
Authorized User
 
Join Date: Aug 2010
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Cade_Feng
Post Sp create temp table?

How to create a temp table in store procedure and insert data in this table?
__________________
Wana be a .net developer.
Sincere yours
Cade_Feng
 
Old September 24th, 2010, 05:18 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

2 ways to create temp table:
Code:
declare @myTable Table(userid int,user_name varchar(20))
insert into @myTable values(1,'user-1')
insert into @myTable values(2,'user-2')
select * from @myTable 
--you can also insert from physical table
insert into @myTable select field1, field2 from table_name
Create Table #myTable (userid int,user_name varchar(20))
insert into #myTable values(1,'user-1')
insert into #myTable values(2,'user-2')
select * from #myTable 
--you can also insert from physical table
insert into #myTable select field1, field2 from table_name
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.
 
Old September 24th, 2010, 02:30 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I don't think that syntax works in MySQL 4.1, which is what Cade Feng is using.

I think in 4.1 you really have to use
Code:
CREATE TEMPORARY TABLE myTable (userid int,user_name varchar(20))
But I'll be happy to be proven wrong.
 
Old September 25th, 2010, 07:40 AM
Authorized User
 
Join Date: Aug 2010
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Cade_Feng
Thumbs up

Thank u very much.It worked.
__________________
Wana be a .net developer.
Sincere yours
Cade_Feng





Similar Threads
Thread Thread Starter Forum Replies Last Post
TEMP TABLE TO REAL TABLE pallone SQL Server 2000 2 June 15th, 2007 07:50 AM
Copy whole structure of table in #temp table maulik77 SQL Server 2000 2 December 21st, 2006 02:42 AM
global temp table vs.permanent table use sofya SQL Server 2000 0 December 17th, 2004 01:57 PM
CREATE TEMP TABLE USING SQL opuspocus SQL Language 1 November 25th, 2004 05:32 AM
CREATE TEMP TABLE USING SQL opuspocus SQL Server 2000 4 November 9th, 2004 08:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.