table-variable

CTE (Common Table Expression) vs Temp tables or Table variables, which is faster?

天涯浪子 提交于 2020-06-10 02:51:28
问题 CTE (Common Table Expression) vs Temp tables or Table variables , which is faster? 回答1: We got a 50% increase in speed moving to CTE in one particular case so it's worth giving it a go but any performance related enhancements need to be bench marked so you can compare one against another. PS: we wrote more than one query with a CTE in it before we got the one we now use. 回答2: As I already said in my comment: IT DEPENDS! It really does depend on your query, your data (how much is there? What

Loading CSV file data into a Table Variable (Index-by table) in Oracle

左心房为你撑大大i 提交于 2020-01-05 05:27:33
问题 My requirement is that I need to read the CSV file data and query it with one existing table in the Database to update some records. One approach I thought that to create a new table (temp) and load the CSV file into that table and query that with the existing table but I found that I don't have permission to create a new table or a directory (for external table approach). Then I thought of doing this through a table variable but I'm not getting how to load the data into a table variable. I

Loading CSV file data into a Table Variable (Index-by table) in Oracle

丶灬走出姿态 提交于 2020-01-05 05:27:08
问题 My requirement is that I need to read the CSV file data and query it with one existing table in the Database to update some records. One approach I thought that to create a new table (temp) and load the CSV file into that table and query that with the existing table but I found that I don't have permission to create a new table or a directory (for external table approach). Then I thought of doing this through a table variable but I'm not getting how to load the data into a table variable. I

Must declare the scalar variable when referencing a table valued parameter

巧了我就是萌 提交于 2019-12-24 08:19:04
问题 This question follows from this one. The following SQL works: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[Update_Repair_Details] @RepairID BIGINT, @NewDetails NewDetails READONLY AS BEGIN SET NOCOUNT ON; DELETE FROM Repair_Details WHERE RepairID = @RepairID INSERT INTO Repair_Details SELECT *, GETDATE() FROM @NewDetails END But since RepairID is the first column in the user-defined table type, there is no reason to pass it as an additional parameter. Thus I wrote:

In T-SQL, how to reference to table variable in the subquery?

假如想象 提交于 2019-12-24 00:34:46
问题 I've declared a table variable '@t', and have correctly performed the 'INSERT-INTO-SELECT'. When I was trying to query the table variable with some additional computation for per-group row numbering, I got error either "Must declare the variable" when using '@t' directly or "invalid object name" while using alias of '@t'. Please kindly advise. SELECT *, (SELECT COUNT(*) FROM "LTV" "COUNTER" WHERE "COUNTER"."Collateral_ID" = "LTV"."Collateral_ID" AND "COUNTER"."m_il_no" = "LTV"."m_il_no" AND

Inserting multiple rows into a SQL Server table using a table variable

半城伤御伤魂 提交于 2019-12-22 05:29:15
问题 I am currently using SQL Server 2008, and I am trying to create a statement using a table variable to insert multiple rows into the table. As it stands right now, I have to insert the information being added in 4 different spots(2 select statements, 1 insert and 1 update), but would like to be able to create a single table variable, so I only have to enter the information once. Any help/suggestions would be greatly appreciated. This is an example of what I am trying to change. PRINT 'Before'

Using a table variable inside of a exists statement

核能气质少年 提交于 2019-12-21 07:36:20
问题 I am trying to update a column inside of a table variable based on a condition, the condition being that the ID of the table variable does not exist in a different table: DECLARE @BugRep TABLE(BugCode VARCHAR(50),DevFirstName VARCHAR(50), DevLastName VARCHAR(50), BugDate VARCHAR(20), IsValid VARCHAR(1)) UPDATE @BugRep SET IsValid = 'N' WHERE NOT EXISTS(SELECT * FROM BUG b WHERE @BugRep.BUGCODE = b.CODE) When i try to compile the procedure that has these statements, I get a "Must declare the

How to view data in table variables during debugging session in MS SQL Management Studio 2012?

心不动则不痛 提交于 2019-12-21 07:14:03
问题 I would like to debug a complex T-SQL script using SSMS 2012. I can run the script in debug mode and place breakpoints, as well as step through my script, but I can't see the values stored in my table variables. In the Locals window I see all these variables, but their value is shown as (table) : There is no way to view the content of the variable through the context menu or by clicking on the variable. I tried to use the Immediate Window to run a query on the table variable, but this seems

RODBC command 'sqlQuery' has problems with table variables in t-SQL

杀马特。学长 韩版系。学妹 提交于 2019-12-19 09:19:34
问题 I am using the RODBC package which I am applying on a Microsoft SQL Server 2012. Now I have discovered a phenomenon that puzzles me. If I run the following query with the RODBC command sqlQuery, then, in R, I will get back an empty data frame with the columns Country, CID, PriceID and WindID. DECLARE @tbl_IDs TABLE ( Country nvarchar(30), CID nvarchar(5), PriceID int, WindID int ) SELECT * FROM @tbl_Ids So far, everything is fine. However, if I try to write a record to the table variable and

SELECT INTO a table variable in T-SQL

雨燕双飞 提交于 2019-12-17 08:02:25
问题 Got a complex SELECT query, from which I would like to insert all rows into a table variable, but T-SQL doesn't allow it. Along the same lines, you cannot use a table variable with SELECT INTO or INSERT EXEC queries. http://odetocode.com/Articles/365.aspx Short example: declare @userData TABLE( name varchar(30) NOT NULL, oldlocation varchar(30) NOT NULL ) SELECT name, location INTO @userData FROM myTable INNER JOIN otherTable ON ... WHERE age > 30 The data in the table variable would be later