Questions tagged [temp-tables]

Temporary tables are a feature of RDBMS's as a means of storing intermediate results. Some RDBMS's make the distinction between local and global temporary tables. Temporary tables are typically dropped when the session ends for local, or when the temporary table is no longer referenced for global. Note that a temporary table is not the same as a table variable even though both are temporary in nature.

The term temporary table is somewhat misleading, because the tables are permanent, just the data is somewhat volatile.

Temporary tables are useful to store intermediate data. Since it only exists for a session or a transaction the RDBMS doesn't have to worry about locks in order to synchronize between different transactions or redo information. This makes temporary tables often faster and more efficient then normal tables.

1496 questions
-1
votes
2 answers

PL/SQL Creating a procedure that contains result set joins

I want to create a procedure in PL/SQL that has 5 steps. Step 1 and 2 execute first and return an ID. In step 3, we have a SELECT statement that has a condition with that returned ID. I want then to take all of the results of that SELECT statement…
PentaKon
  • 3,359
  • 3
  • 32
  • 64
-1
votes
1 answer

How to create temp table with data from 1 tables and with some variables

I am trying to create a temp table. SET @pstartDate = '01-01-2013' SET @pendDate = '31-12-2013' SET @cstartDate = '01-01-2014' SET @cendDate = '31-12-2014' CREATE TABLE #Temp ( pId int, pname varchar, ptype varchar, …
sms
  • 91
  • 1
  • 6
-1
votes
1 answer

program runs fine with no errors but not giving me the result i want

I am trying to take the data from my datatable and sqlbulkcopy it to a temp table then from temp table insert to the main table but when I run the program it runs through but it is not populating the end database table: static void Main(string[]…
HackGod555
  • 134
  • 10
-1
votes
1 answer

SQL SELECT results INTO temp table using query string

I am trying to write some dynamic SQL queries that select results into a temp table with a query string. It looks like follows: DECLARE @SQL Varchar(4000) SET @SQL = 'SELECT * INTO #tmp_tab FROM dbo.sometable' EXEC(@SQL) It doesn't give any error…
ChangeMyName
  • 5,012
  • 12
  • 46
  • 87
-1
votes
2 answers

SQL: Using CONCAT to merge 2 columns, then putting the result into a temp table & column

INSERT INTO #TempTable (Name) SELECT CONCAT(FirstName, ' ', LastName) As Name from tbl_name I've tried to do this in a number of different variations and can't get it to work. Please can somebody assist?
helpme
  • 1
  • 1
-1
votes
2 answers

Cannot create the same #temp table twice in the same batch

Wrote a very simple test case in SQLServer and don't quite understand why it doesn't work: create table #temp( id int, val int) insert into #temp values (1, 1), (2, 2) select * from #temp if object_id('tempdb..#temp') is not null drop table…
kchang
  • 93
  • 3
  • 10
-1
votes
1 answer

MySQL multi statement in PHP

What happens is that I'm working with google maps api and I have a database with some shops, the database is the direction of these, that with a javascript get the distance between the store and the location of user, the topic I want to sort by…
Blaztix
  • 1,034
  • 1
  • 15
  • 25
-1
votes
3 answers

Unable to copy data to temporary table using select statement in sql - server 2008

I am copying the data to temporary table using select statement which produces the result of pivoting. My procedure is: alter procedure proc11 AS create Table #Temp (Software varchar(max), Ver varchar(max)) declare @cols varchar(max) declare…
Mohemmad K
  • 759
  • 7
  • 29
  • 68
-1
votes
3 answers

Couldn't create temp table from select query if result empty

I want to crate a temp table from select query (My table has many columns, therefore I don't want to create the temp table manually) I use the following query: SELECT * INTO #TempTable FROM MyTable WHERE ... If this query return empty rows, it…
Jin Ho
  • 3,317
  • 5
  • 21
  • 23
-1
votes
1 answer

SQL Keyword Search to Return Any Results

I have created a keyword search in SQL that takes a list of keywords and checks against various columns in the product database. So you can search the title, description, etc. I'd like it to return all results and skip results where there is nothing…
User970008
  • 1,253
  • 3
  • 20
  • 46
-2
votes
2 answers

Create a temp table in a view that holds number 1 to 1000

I need to create a temporary table inside of a view that has one column with number one to 1000. Any ideas on how to do this? I am using SQL Server. Thanks.
sye
  • 153
  • 3
  • 9
-2
votes
1 answer

How to get the results of selection from a temporary table Ordered by a specific field?

I mean how to reference specific columns in a temporary table in Oracle ?
-2
votes
3 answers

How to insert rows from one temp table to another in sql

ID LogDate LogTime InoutMode 1 2017-02-23 19:30:00.0000000 1 2 2017-02-23 20:00:00.0000000 0 3 2017-02-23 20:30:00.0000000 1 4 2017-02-23 21:00:00.0000000 0 5 …
user7629904
-2
votes
1 answer

How to create temp table with select query update it and the insert it in mysql?

Can anyone tell me why this doesn't work Create Procedure LeaveUpdate() Begin CREATE TEMPORARY TABLE leavebal AS (SELECT * FROM tbl_leave_balance WHERE month = month(DATE_SUB(now(), INTERVAL 1 MONTH)) and year = year(DATE_SUB(now(), INTERVAL 1…
-2
votes
1 answer

T-SQL select into temp table does not have correct result

-- This Result Is Right and work correctly: SELECT AutoId, Name,[Group],[Priority], SUMCalculatedPercent FROM (SELECT DISTINCT *, ROW_NUMBER() OVER ( PARTITION BY [Group] ORDER BY SUMCalculatedPercent DESC,[Priority] ) AS ranker FROM…
A.J
  • 89
  • 1
  • 1
  • 9
1 2 3
99
100