temp-tables

INSERT INTO temp table from unknown number and name of columns (from dynamic PIVOT query)

孤者浪人 提交于 2019-12-13 03:36:14
问题 I have a dynamic query as shown below. The @ColumnNames param has multiple columns this pivot is using. @ID and @Apartment_ID come from insert parameters. SET @DynamicSQL = 'select id, name, address, phone, remarks, ' + **@ColumnNames** + ' from (select b.id, name, criteria_id, impact_value, remarks from dbo.User u inner join dbo.ID b on b.id = u.id where b.Instance_ID = '+ **@Id** + 'and ownerID in (select * from fnSplitString(''' + **@Apartment_ID** + + ''',' + ''',''' + '))' + ') as t

Why do I get no results when returning the results of a Stored Proc?

≡放荡痞女 提交于 2019-12-12 22:34:44
问题 In the first step of what will build up to include several temp tables and Stored Procs being called and then Unioned, I have the first baby steps (based on the answer from Philip Kelley here): IF OBJECT_ID ( 'RockBottomAmalgamated', 'P' ) IS NOT NULL DROP PROCEDURE RockBottomAmalgamated; GO CREATE PROC [dbo].[RockBottomAmalgamated] @BegDate datetime, @EndDate datetime, @SortBy varchar(20) AS CREATE TABLE #BaseCraftworksTable ( Unit varchar(25) not null ,ShortName varchar(50) ,ItemCode

Parameter Mapping using an Execute SQL Task

随声附和 提交于 2019-12-12 19:07:13
问题 I am trying to create a temporary table and insert data into the temp table within an Execute SQL Task inside a foreach loop container. Here are the sql tasks IF OBJECT_ID('TEMPDB.DBO.#TEMP') IS NOT NULL DROP TABLE #TEMP GO CREATE TABLE #TEMP ( ... ); INSERT INTO #TEMP SELECT (...) FROM table t1 INNER JOIN table2 t2 ON t1.id = t2.table1_id WHERE t1.value = ? I want to have a parameter in the WHERE clause but whenever I try to add it I get this error. "Multiple-step OLE DB operation generated

What is the preferred method of creating, using and dropping temp tables in sql server?

冷暖自知 提交于 2019-12-12 13:29:38
问题 When using temp tables in SQL Server stored procs, is the preferred practice to; 1) Create the temp table, populate it, use it then drop it CREATE TABLE #MyTable ( ... ) -- Do stuff DROP TABLE #MyTable 2) Check if it exists, drop it if it does, then create and use it IF object_id('tempdb..#MyTable') IS NOT NULL DROP TABLE #MyTable CREATE TABLE #MyTable ( ... ) 3) Create it and let SQL Server clean it up when it goes out of scope CREATE TABLE #MyTable ( ... ) -- Do Stuff I read in this answer

Can I recreate a temp table after dropping it?

你离开我真会死。 提交于 2019-12-12 11:53:09
问题 Given: code inside a stored proc: select bleh into #tblTemp from FunctionThatReturnsTable('some','params') -- do some stuff drop table #tblTemp -- Error on this command: -- 'There is already an object named '#tblTemp' in the database.' select bleh into #tblTemp from FunctionThatReturnsTable('some','other params') Problem: I can't recreate this temp table. My work around is to use #tmpTable1, #tmpTable2, #tempTable3 etc. Is there a way I can get around this? It would be nice just use one temp

Is it possible to create a temp table on a linked server?

浪子不回头ぞ 提交于 2019-12-12 10:36:35
问题 I'm doing some fairly complex queries against a remote linked server, and it would be useful to be able to store some information in temp tables and then perform joins against it - all with the remote data. Creating the temp tables locally and joining against them over the wire is prohibitively slow. Is it possible to force the temp table to be created on the remote server? Assume I don't have sufficient privileges to create my own real (permanent) tables. 回答1: It's not possible to directly

Inserting data into a temporary table

给你一囗甜甜゛ 提交于 2019-12-12 07:08:07
问题 After having created a temporary table and declaring the data types like so; CREATE TABLE #TempTable( ID int, Date datetime, Name char(20)) How do I then insert the relevant data which is already held on a physical table within the database? 回答1: INSERT INTO #TempTable (ID, Date, Name) SELECT id, date, name FROM physical_table 回答2: To insert all data from all columns, just use this: SELECT * INTO #TempTable FROM OriginalTable Don't forget to DROP the temporary table after you have finished

DB2 9.7 SQL syntax, what am I doing wrong?

泪湿孤枕 提交于 2019-12-12 03:33:29
问题 For one reason or other which are out of my control I am attempting to simply pull data over the past 12 months. However, essentially down to the size of data, I have to query each day into a temp table and go from there. Now I'm a newbie to scripting in DB2, but not SQL in general, so I've tried the code below (the logic seems fine to me). Initially I'm was just interested in how many records will be generated, but ideally I'd want to run the second SELECT code. I've been using Data Studio,

How to check for output table of called stored procedure?

萝らか妹 提交于 2019-12-12 02:33:43
问题 Simple scenario. Stored procedure sp_Task1 calls sp_Task2 , and sp_Task2 has an output temp table called #Task2_Output . I want sp_Task1 to take #Task2_Output and perform further transactions with it. How do I get these two things to happen: 1) Make sure sp_Task1 waits until sp_Task2 is completed to move on to the next line of code. 2) How to check that #Task2_Output was successfully created from code within sp_Task1 . 回答1: Since you don't mention which DBMS, I assume it is SQL Server, since

mysql & php: temporary/ virtual ids for query results?

不羁的心 提交于 2019-12-12 01:29:20
问题 I wonder if it is possible to assign temporary/ virtual IDs for a query result? For instance, I have this as my query, SELECT pg_id AS ID, pg_url AS URL, pg_title AS Title, pg_content_1 AS Content FROM root_pages ORDER BY pg_created DESC output: ID URL Title Content 53 a A xxx 40 b B xxx 35 c C xxx you can see the the gap between the IDs - they are very untidy. I wonder if I can make a virtual column or something so that I have the output below, ID URL Title Content Virtual ID 53 a A xxx 3 40