temporary-tables

How to retrieve field names from temporary table (SQL Server 2008)

I'm using SQL Server 2008. Say I create a temporary table like this one: create table #MyTempTable (col1 int,col2 varchar(10)) How can I retrieve the list of fields dynamically? I would like to see something like this: Fields: col1 col2 I was thinking of querying sys.columns but it doesn't seem to store any info about temporary ...

How to group data from temporary table

Hi guys, I have created one temporary table in which corresponding to one fileid which is primary key, I am having 5 rows. I want to get the count as 5. What query do I have to write to get the count corresponding to each fileid? ...

Can you define "literal" tables in SQL?

Is there any SQL subquery syntax that lets you define, literally, a temporary table? For example, something like SELECT MAX(count) AS max, COUNT(*) AS count FROM ( (1 AS id, 7 AS count), (2, 6), (3, 13), (4, 12), (5, 9) ) AS mytable INNER JOIN someothertable ON someothertable.id=mytable.id This would sav...

Temporary tables in Linq -- Anyone see a problem with this?

In trying to solve: Linq .Contains with large set causes TDS error I think I've stumbled across a solution, and I'd like to see if it's a kosher way of approaching the problem. (short summary) I'd like to linq-join against a list of record id's that aren't (wholly or at least easily) generated in SQL. It's a big list and frequently ...

Insert into a table a part of another table

I have two tables, the structure of the first partially recapitulates, iterates the structure of the second: table1 (id, i, j, k, a, b, c, x, y, z) -- requests table2 (id, a, b, c, d) -- essential elements / bank subjects I need to insert into table1 a record from table2 with given ID. What is the best approach to do that? I have two...

Pulling items out of a DB with weighted chance

Let's say I had a table full of records that I wanted to pull random records from. However, I want certain rows in that table to appear more often than others (and which ones vary by user). What's the best way to go about this, using SQL? The only way I can think of is to create a temporary table, fill it with the rows I want to be more...

Local Temporary table in Oracle 10 (for the scope of Stored Procedure)

I am new to oracle. I need to process large amount of data in stored proc. I am considering using Temporary tables. I am using connection pooling and the application is multi-threaded. Is there a way to create temporary tables in a way that different table instances are created for every call to the stored procedure, so that data from ...

Stored procedure and .NET: SELECT INTO on temporary table: suppress result

I'm accessing a stored procedure from ADO.NET. The stored procedure should eventually returns a single result set. To compute this result, a temporary table is filled with a SELECT INTO statement. The problem is that the result of the SELECT INTO statement is also returned as a result set to .NET. Can this be suppressed? Or should I...

How to tell what temporary tables are currently in scope in SQL Server?

I often get the errors: Msg 208, Level 16, State 0, Line 1 Invalid object name '#foo'. Msg 3701, Level 11, State 5, Line 1 Cannot drop the table '#foo', because it does not exist in the system catalog. How do I know what temporary tables there are in scope? They obviosly don't show up in SSMS like base tables do. ...

Sql server - how to insert single row into temporary table?

Hello, I have two temporary table, when i do cycle through one table and i get some values from it, in this cycle I need insert new row into another temporary table. Is this possible. Here is my sql code and error information: Alter PROCEDURE ProfitReportQ_Search_WithSub (@DateFrom datetime, @DateTo datetime, @DateActive bit, @User...

MySql: Problem when using a temporary table

Hi, I'm trying to use a temporary tables to store some values I need for a query. The reason of using a temporary table is that I don't want to store the data permanently so different users can modify it at the same time. That data is just stored for a second, so I think a temporary table is the best approach for this. The thing is that...

SQL Server SELECT INTO and Blocking With Temp Tables

So, recently a DBA is trying to tell us that we cannot use the syntax of SELECT X, Y, Z INTO #MyTable FROM YourTable To create temporary tables in our environment, because that syntax causes a lock on TempDB for the duration of the stored procedure executing. Now, I've found a number of things that detail how temporary tables work, s...

MySQL connection pooling and creating temporary table.

I already set up MySQL connection pool in Glassfish using JNDI. I only execute one query at a time but use the same sql instance. Everything seems to work fine except creating temporary tables and use them. In short, even though after I create a temporary table, insert query does not work since the table does not exist. Are there any con...

SQL Oracle statement optimized with temporary table

Hello there, I have optimized a complex Oracle statement using temporary table like this : original : SELECT data FROM table WHERE ..complex statement..; optimized (I can't use WITH keyword, because I deal with < Oracle9i) : CREATE GLOBAL TEMPORARY TABLE temptab (x NUMBER, y DATE) ON COMMIT DELETE ROWS; INSERT INTO temptab SELECT ...

How to return temporary table from stored procedure

CREATE PROCEDURE [test].[proc] @ConfiguredContentId int, @NumberOfGames int AS BEGIN SET NOCOUNT ON RETURN @WunNumbers TABLE (WinNumb int) INSERT INTO @WunNumbers (WinNumb) SELECT TOP (@NumberOfGames) WinningNumber FROM [Game].[Game] g JOIN [Game].[RouletteResult] AS rr ON g.[Id] = rr.[gameId] WHERE g.[ConfiguredContentId] =...

Entity Framework, full-text search and temporary tables

I have a LINQ-2-Entity query builder, nesting different kinds of Where clauses depending on a fairly complex search form. Works great so far. Now I need to use a SQL Server fulltext search index in some of my queries. Is there any chance to add the search term directly to the LINQ query, and have the score available as a selectable prop...

My SQL Using temporary tables with PHP without mysql_pconnect

I want to use temporary tables in my PHP code. It is a form that will be mailed. I do use session variables and arrays but some data filled in must be stored in a table format and the user must be able to delete entries in case of typos etc. doing this with arrays could work (not sure) but I'm kinda new at the php and using tables seems ...

How to save a single result set to a temp table from a SQL stored procedure returning multiple sets?

I need to store the result set of a stored procedure in a temporary table (using SQL Server 2000). From what I've read, this (poorly constructed example) should work: create table #tempTable (TempId int primary key, Column1 varchar(100), Column2 varchar(100), DateCreated datetime) insert into #tempTable (TempId, Column1, Column2, Dat...

Global Temporary table delete operation

How to check if the global Temporary table exists in SQL server, if yes then delete that global temporary table? I am trying to execute this: IF OBJECT_ID('##Table', 'U') IS NOT NULL DROP TABLE ##Table ...but it is not working. ...

What is the difference between TEMPORARY TABLE and TABLE VARIABLE in SQL 2008?

What is the difference between: CREATE TABLE #temp ( [ID] INT) INSERT INTO #temp SELECT ... and DECLARE @temp TABLE ( [ID] INT) INSERT @temp SELECT ... in SQL Server 2008? ...