temp-tables

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 08:47:46
问题 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 tables. Any ideas? 回答1: select * from tempdb.sys.columns where object_id = object_id('tempdb..#mytemptable'); 回答2: select * from tempdb.INFORMATION_SCHEMA.COLUMNS

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

ε祈祈猫儿з 提交于 2019-12-17 08:46:08
问题 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 tables. Any ideas? 回答1: select * from tempdb.sys.columns where object_id = object_id('tempdb..#mytemptable'); 回答2: select * from tempdb.INFORMATION_SCHEMA.COLUMNS

EF4 - The selected stored procedure returns no columns

我怕爱的太早我们不能终老 提交于 2019-12-17 02:11:56
问题 I have query in a stored procedure that calls some linked servers with some dynamic SQL. I understand that EF doesn't like that, so I specifically listed all the columns that would be returned. Yet, it still doesn't like that. What am I doing wrong here? I just want EF to be able to detect the columns returned from the stored procedure so I can create the classes I need. Please see the following code that makes up the last lines of my stored procedure: SELECT #TempMain.ID, #TempMain.Class

EF4 - The selected stored procedure returns no columns

泄露秘密 提交于 2019-12-17 02:11:14
问题 I have query in a stored procedure that calls some linked servers with some dynamic SQL. I understand that EF doesn't like that, so I specifically listed all the columns that would be returned. Yet, it still doesn't like that. What am I doing wrong here? I just want EF to be able to detect the columns returned from the stored procedure so I can create the classes I need. Please see the following code that makes up the last lines of my stored procedure: SELECT #TempMain.ID, #TempMain.Class

Why does a global temp table created by an SSIS package disappear after completion? [closed]

大兔子大兔子 提交于 2019-12-14 04:02:09
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . At the start of ETL package the following SQL query runs against a SQL Server 2012 database: IF OBJECT_ID(N'tempdb..##SlotChanges') IS NOT NULL BEGIN DROP TABLE ##SlotChanges END CREATE TABLE ##SlotChanges ( --Snip ) The package then writes some rows to the temp table and uses it as the final data source when

Issue working with temporary table

守給你的承諾、 提交于 2019-12-14 03:54:01
问题 I enter the following into phpMyAdmin: CREATE TEMPORARY TABLE test_table ( item1 VARCHAR(50) NOT NULL , item2 DECIMAL(12,2) NOT NULL DEFAULT 0.00 , item3 DECIMAL(7,2) NOT NULL DEFAULT 0.00 , item4 INT UNSIGNED NOT NULL DEFAULT 0); The table is successfully created. Then I enter the following statement also into phpMyAdmin: INSERT INTO test_table (item1, item2, item3, item4) VALUES ('lentils', 99.00, 82, 8); And I receive; "#1146 - Table 'mydatabase.test_table' doesn't exist" Any clues as to

Creating a temporary table name with a randomly generated number

安稳与你 提交于 2019-12-13 13:56:37
问题 So far I have this code: declare @random int, @upper int, @lower int, @rndtb varchar(20) set @lower = 1 set @upper = 999 select @random = ROUND(((@upper - @lower) * rand() + @lower),0) select @rndtb = '##show'+cast(@random as varchar(20))+'' But that gives me Conversion failed when converting the varchar value '##show' to data type int. What I am trying to achieve is to create a table ##show+random number each time the query is executed. Example : ##show01 ##show78 ##show43 Edited with what

Dynamic creation of table in tsql

守給你的承諾、 提交于 2019-12-13 06:39:07
问题 I am trying to create a temptable dynamically in tsql . I have a query which gives me some data (as a result of another dynamic query ) in a column. For example say years like 2011/2012 . This will be in a column. What i want is to pick value of each row and name it as a column name of type int. Later , i can use that temp table to dump data into it. Any suggestions? 回答1: Would you be able to use something like this? DECLARE @Tab VARCHAR(MAX) SET @Tab = 'CREATE TABLE #Whatever (' SELECT @Tab

Check if declared global temporary table exists in current session

左心房为你撑大大i 提交于 2019-12-13 05:53:38
问题 How can I check if a declared global temporary table in DB2 exists or not in the current session? I need to create the temporary table once for a user session and then be able to insert rows in it each time a report is executed in the case of my application. So I need to delete all the rows from this table when a report is executed for more than the first time and then re-populate it with new rows. Right now the method creating the temporary table is throwing a 42710 SQLSTATE error the second

Creating a Table with Points from X and Y Coordinates and Joining to a Table of Polygons if Point Withing Polygon

做~自己de王妃 提交于 2019-12-13 03:39:58
问题 I am attempting to be create a polygon table of hexagons, with a name for each hexagon (e.g. Hex1, Hex2, etc...) and join the polygon table to a table of records that have x and y coordinates if the coordinates fall within a polygon. Creating the hex table with the code below, when ran in isolation, seems to be working (except for some of my numbers being off, creating some overlap) DECLARE @Hex TABLE --Create table to old hexagons (PointGeom geometry, Hex varchar(6)) INSERT INTO @Hex -