Check if a temporary table exists and delete if it exists before creating a temporary table

I cannot reproduce the error. Perhaps I’m not understanding the problem. The following works fine for me in SQL Server 2005, with the extra “foo” column appearing in the second select result: IF OBJECT_ID(‘tempdb..#Results’) IS NOT NULL DROP TABLE #Results GO CREATE TABLE #Results ( Company CHAR(3), StepId TINYINT, FieldId TINYINT ) GO select company, … Read more

EF can’t infer return schema from Stored Procedure selecting from a #temp table

CREATE PROCEDURE [MySPROC] AS BEGIN –supplying a data contract IF 1 = 2 BEGIN SELECT cast(null as bigint) as MyPrimaryKey, cast(null as int) as OtherColumn WHERE 1 = 2 END CREATE TABLE #tempSubset( [MyPrimaryKey] [bigint] NOT NULL, [OtherColumn] [int] NOT NULL) INSERT INTO #tempSubset (MyPrimaryKey, OtherColumn) SELECT SomePrimaryKey, SomeColumn FROM SomeHugeTable WHERE LimitingCondition = true … Read more

Creating temporary tables in SQL

You probably want CREATE TABLE AS – also works for TEMPORARY (TEMP) tables: CREATE TEMP TABLE temp1 AS SELECT dataid , register_type , timestamp_localtime , read_value_avg FROM rawdata.egauge WHERE register_type LIKE ‘%gen%’ ORDER BY dataid, timestamp_localtime; This creates a temporary table and copies data into it. A static snapshot of the data, mind you. It’s … Read more

EF4 – The selected stored procedure returns no columns

EF doesn’t support importing stored procedures which build result set from: Dynamic queries Temporary tables The reason is that to import the procedure EF must execute it. Such operation can be dangerous because it can trigger some changes in the database. Because of that EF uses special SQL command before it executes the stored procedure: … Read more

How can I simulate an array variable in MySQL?

Well, I’ve been using temporary tables instead of array variables. Not the greatest solution, but it works. Note that you don’t need to formally define their fields, just create them using a SELECT: DROP TEMPORARY TABLE IF EXISTS my_temp_table; CREATE TEMPORARY TABLE my_temp_table SELECT first_name FROM people WHERE last_name=”Smith”; (See also Create temporary table from … Read more