Questions tagged [table-variable]

A SQL Server local variable that can store rows.

From MSDN:

Is a special data type that can be used to store a result set for processing at a later time. table is primarily used for temporary storage of a set of rows returned as the result set of a table-valued function.

A table variable differs from a "temporary table" in that it has

  • no statistics
  • limited index options
  • execution plans often assume single row
  • does not participate in user transactions
  • for the batch/proc scope only
170 questions
0
votes
3 answers

TSQL set the column value of a table variable

I am trying to set individual columns of a table variable iteratively as follows: declare @reg_data table ( I int NOT NULL PRIMARY KEY IDENTITY, Y float ) declare @counter int, @numRows int SET @counter = 0 SET @numRows = (select MAX(val) +…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
-1
votes
1 answer

I am facing a weird problem when inserting data from an SQL Stored procedure into a table variable

I have this stored procedure: Lemma 1: exec GetData 1, '20220301', 1 I run it with 1 as one of the parameters, It does correctly return some data Lemma 2: exec GetData 1, '20220301', 15 I run it with other parameter (15), it returns the same table…
-1
votes
1 answer

SQL query with Table variable/Temp Table - which one good in performance

SQL Questions: Is this insert query is good in performance ? UserIds List is variable, its length mybe 10, 20 ... till 500. WITH Users AS (SELECT [Id] from [electro].[User] Where [Id] IN (4438,15473,22497,22494,4425,4426,22496)) INSERT INTO…
-1
votes
1 answer

Sending the stored procedure output as comma-separated rather than multiple rows

I have a stored procedure that returns multiple rows with 5 columns: SELECT Travel, ID, Dept, Role, Country FROM TravelManager For example, I get: DName ID Dept Role Country ---------------------------------- Travel 23 HR H …
Jasmine
  • 5,186
  • 16
  • 62
  • 114
-1
votes
1 answer

What is that makes temp tables more efficient than table variables when working with large data?

In SQL Server, the performance of temp tables is much better (in the means of time) compared to table variables when working with large data (say inserting or updating 100000 rows) (reference: SQL Server Temp Table vs Table Variable Performance…
user1080381
  • 1,597
  • 1
  • 16
  • 22
1 2 3
11
12